2012-02-02 72 views
0

我想旋转我的UIView子类的实例,然后用动画对其进行缩放。不幸的是我的代码在同一个动画中旋转和缩放。 如何在任何缩放动画发生之前完成或强制旋转?在动画发生之前旋转UIView

- (void) layoutSubviews { 
    self.transform = CGAffineTransformMakeRotation(myAngle); 

    // other layout... 
} 

- (void) showMyView { 
    [UIView setAnimationCurve:something]; 
    [UIView setAnimationDuration:somethingElse]; 

    self.layer.transform = CATransform3DMakeScale(x, y, z); 

    [UIView commitAnimations]; 
} 

回答

3

首先,苹果推荐使用Block语法来制作动画。
除此之外,它更容易实现你想要的。

首先为您的旋转制作动画,如果完成,请制作缩放内容。
代码示例:

[UIView animateWithDuration:0.5 
       animations:^{ 
        // This rotates the layer by 90° 
        self.layer.transform = CGAffineTransformMakeRotation(M_PI/2.0); 
       } 
       // On completition start the scaling 
       completion:^(BOOL finished){ 
        if (finished) { 
         [UIView animateWithDuration:0.5 
              animations:^{ 
               // This scales 
               self.layer.transform = CGAffineTransformMakeScale(2.0, 2.0); 
              } 
          ]; 
        } 
       } 
    ]; 

也可以与您使用的“老字号”动画风格,但它实现起来更复杂动画的代表等等

+0

啊好主意。在上面的代码中,第一个动画持续时间可以是零? – SundayMonday 2012-02-03 00:29:42

+1

是的,但在这种情况下,您实际上不需要为其制作动画。 只需将旋转添加到视图中,然后再开始第二个动画。 – yinkou 2012-02-03 01:02:24