gpt4 book ai didi

IOS:延迟动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:30 25 4
gpt4 key购买 nike

我想知道最好的方法是什么:

你有这个功能:

- (void)launchAirplane:(int)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. CADiplayLink。

最佳答案

我会以不同的方式来做:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com