2012-06-10 45 views
3

我想用動畫發送超級UIView的子視圖,它工作正常,但是當我試圖在動畫期間更改任何UILabel時,我在子視圖中突然變得太小。 這裏是我的代碼當父母UIView動畫時,UILabel大小突然變化

-(void)pushOutScreen:(UIViewController *)pop{ 
    [UIView animateWithDuration:1 
         delay:0.0 
        options: UIViewAnimationTransitionFlipFromLeft 
       animations:^{ 

        CGRect frame = pop.view.frame; 
        frame.size.height = frame.size.height /4; 
        frame.size.width = frame.size.width /4; 
        frame.origin.x = -500; 
        frame.origin.y = 318; 

        pop.view.frame = frame; 
       } 
       completion:^(BOOL finished){ 
        NSLog(@"Done!"); 
       }]; 
} 

音聲部:任何UIButtonUIImage這是在我的子視圖動畫不錯,但我只有用UILabel問題。

回答

2

UIView動畫不適合做這個選項,而不是嘗試CAKeyframeAnimation。這是縮放UIView示例代碼:

- (void) scaleView:(UIView *)popView { 
    CAKeyframeAnimation *animation = [CAKeyframeAnimation 
            animationWithKeyPath:@"transform"]; 
    animation.delegate = self; 

    // CATransform3DMakeScale has 3 parameter (x,y,z) 
    CATransform3D scale1 = CATransform3DMakeScale(1.0, 1.0, 1); 
    CATransform3D scale2 = CATransform3DMakeScale(0.2, 0.2, 1); 

    NSArray *frameValues = [NSArray arrayWithObjects: 
         [NSValue valueWithCATransform3D:scale1], 
         [NSValue valueWithCATransform3D:scale2], 
         nil]; 
    [animation setValues:frameValues]; 

    NSArray *frameTimes = [NSArray arrayWithObjects: 
         [NSNumber numberWithFloat:0.0], 
         [NSNumber numberWithFloat:1.0], 
         nil];  
    [animation setKeyTimes:frameTimes]; 

    animation.fillMode = kCAFillModeForwards; 
    animation.removedOnCompletion = NO; 
    animation.duration = 1.0; 

    [popView.layer addAnimation:animation forKey:@"popup"]; 
} 

您添加UIViewsubView那麼你可以調用此方法,因爲它的規模後,您可以使用此。爲了用此方法推出子視圖,在動畫完成後需要使用removeFromSubView。 知道當它完成使用時

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 
{ 
    [subView removeFromSuperview]; 
} 

我希望它是有用的!

+0

謝謝老兄,最後有人回答了我的問題。你寫的解決方案是正確的。我只是對它進行編輯,確切地說是我的問題和答案。 – nfarshchi

+1

但這個代碼中有什麼是'animation.fillMode'做的問題?我仍然懷疑 – nfarshchi

+0

'forwards'等同於現有的'frozen','backwards'將零之前的時間值鉗位到零,'both'鉗住對象時間空間兩端的時間值! –