performSelector的替代方法:withObject:afterDelay:用于为视图制作动画

时间:2013-09-20 06:51:39

标签: ios objective-c animation

我的方法-(void)animationStart包含许多具有不同方法和延迟的[self performSelector:@selector(myAnimation) withObject:nil afterDelay: 21 * 0.01];

如何重构我的代码而不使用performSelector?我用它来制作动画,从而改变。

1 个答案:

答案 0 :(得分:2)

您没有指定自己如何完全执行动画,但使用 UIView动画块,您还可以指定延迟。(animateWithDuration:delay:options:animations:completion:)。

或者,您可以使用NSTimer执行延迟。

但是要获得详细答案,您应该提供有关如何执行动画的更多详细信息。

<强>更新

使用动画块非常简单......在完成块(参见下面的代码)中,您可以开始跟进动画(用于一系列动画)。对于并行动画处理,您只需启动多个动画块...有不同的消息。如果您不需要处理动画结束,则可以使用没有完成块的那些。

以下是一个例子:

[UIView animateWithDuration:2.0 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{

    // perform animation code here

} completion:^(BOOL finished) {

    // This code is performed after the animation is completed. E.g. you can start a new animation here
    // (for serial animation processing):

}];