菜鸟教程小白 发表于 2022-12-12 14:38:27

IOS:延迟动画


                                            <p><p>我想知道最好的方法是:</p>

<p>你有这个功能:</p>

<pre><code>- (void)launchAirplane:(int)whichAirplane {

// Add score lables
// Start particle effect
// Move airplane (whichAirplane)
// Remove airplan
}
</code></pre>

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

<p>所以有几种方法可以做到这一点:</p>

<ol>
<li>将 GCD 与 dispatch_after 一起使用(但 dispatch_after 非常不准确,我注意到 0.1 秒的延迟可能相差高达 30 %)。 </li>
<li>NSTimer</li>
<li>CADiplay 链接。 </li>
</ol></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我会这样做:</p>

<pre><code>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) {

    }];
}];
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于IOS:延迟动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18810165/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18810165/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: IOS:延迟动画