2014-10-08 70 views
-2

我创建了一个叫UIView myView。首先,将其移动到左侧。然后将其移至右侧。我用了两个[UIView animatedWithDuration:delay:animations:^completed:^]。但它没有奏效。为一个UIView,做两个动画,一个接一个地

我问一个资深工程师,他给了我这个解决方案。

[UIView animatedWithDuration: 
        animations: 
          //first animation 
        completed: 
          dispatch_after(.....){ 
           //second animation 
          } 
] 

通过使用dispatch_after(),可以顺序执行两个动画。

回答

4

试试这个:

[UIView animateWithDuration:0.3f animations:^{ 
    self.theView.frame = CGRectMake(10, 10, 100, 100); 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3f animations:^{ 
     self.theView.frame = CGRectMake(200, 10, 100, 100); 
    } completion:nil]; 
}]; 
+0

工程。谢谢。但是,如果逻辑非常复杂,代码将高度嵌套。有没有更好的方法来解决这个问题? – Gonghan 2014-10-08 07:41:56

+0

什么是复杂逻辑?你能描述更多吗? – gabbler 2014-10-08 07:44:13

+0

这就是我想要链接两个动画时的操作,它的作用就像一个魅力。 :) – 2014-10-09 07:24:10