等待动画在iOS完成?

Seb*_*rth 2 animation objective-c ios

我想在动画结束后执行doSomethingElse.另一个限制是动画代码可以具有不同的持续时间.我怎样才能做到这一点?谢谢!

-(void) doAnimationThenSomethingElse {
  [self doAnimation];
  [self doSomethingElse];
}
Run Code Online (Sandbox Code Playgroud)

例如,这不起作用:

animationDuration = 1;
[UIView animateWithDuration:animationDuration
    animations:^{
      [self doAnimation];
    } completion:^(BOOL finished) {
      [self doSomethingElse];
    }
];
Run Code Online (Sandbox Code Playgroud)

mat*_*att 23

如果您不是动画的作者,则可以在动画结束时使用事务完成块获取回调:

[CATransaction setCompletionBlock:^{
     // doSomethingElse
}];
// doSomething
Run Code Online (Sandbox Code Playgroud)


小智 7

使用块动画:

[UIView animateWithDuration:animationDuration
    animations:^{
        // Put animation code here
    } completion:^(BOOL finished) {
        // Put here the code that you want to execute when the animation finishes
    }
];
Run Code Online (Sandbox Code Playgroud)