iOS - 多个动画块?

ary*_*axt 3 uiviewanimation ios

我有多个必须作为链运行的动画.我一直在处理的方法是使用completionHandler并运行下一个动画块.有没有更清洁的方法来处理这个?

[UIView animateWithDuration:1 animations^{

        // perform first animation
     }completion:(BOOL finished){

          [UIView animateWithDuration:1 animations^{

               // perform second animation
          }completion:(BOOL finished){

         }];

}];
Run Code Online (Sandbox Code Playgroud)

Rob*_*ier 10

您也可以使用animateWithDuration:delay:options:animations:completion:交错延迟,以便它们按顺序启动,但通常最好使用完成块来执行它们.

如果有几个并且它使代码难以阅读,只需将块分解出来(我在我的头顶输入它,所以它可能无法编译):

typedef void (^AnimationBlock)();

AnimationBlock firstAnimation = ^{ ... };
AnimationBlock secondAnimation = ^{ ... };

[UIView animateWithDuration:1 animations:firstAnimation completion:(BOOL finished) {
  [UIView animateWithDuration:1 animations:secondAnimation];}];
Run Code Online (Sandbox Code Playgroud)

您可以创建一个类别,UIView其中包含一系列此类块并将它们链接在一起,但是您必须处理所有极端情况.你如何定义时间; 你如何处理流产的动画等.在大多数情况下,上述可能是最好的方法.