OGeek|极客世界-中国程序员成长平台

标题: IOS:延迟动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:38
标题: IOS:延迟动画

我想知道最好的方法是:

你有这个功能:

- (void)launchAirplaneint)whichAirplane {

 // Add score lables 
 // Start particle effect
 // Move airplane (whichAirplane)
 // Remove airplan 
}

您有 10 架飞机,它们彼此相邻。每架飞机应该在前一架飞机之后延迟 0.1 秒发射。所以飞机 1 在 0 秒后发射,飞机 2 在 0.1 秒后发射,飞机 3 在 0.2 秒后发射,等等。

所以有几种方法可以做到这一点:

  1. 将 GCD 与 dispatch_after 一起使用(但 dispatch_after 非常不准确,我注意到 0.1 秒的延迟可能相差高达 30 %)。
  2. NSTimer
  3. CADiplay 链接。



Best Answer-推荐答案


我会这样做:

NSArray *airplanes = ... // here you are initializing your airplanes array
NSTimeInterval *duration = 1.0f;


[airplanes enumerateObjectsUsingBlock:^(Airplane *plane, NSUInteger idx, BOOL *stop) {
    [UIView animateWithDuration:duration delay:0.1 * idx options:0 animations:^{
        // do your airplane animation here
    } completion:^(BOOL finished) {

    }];
}];

关于IOS:延迟动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18810165/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4