Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are many, many ways to do this in iOS/Objective-C. I'm assuming you don't want a callback from the actual audio player guaranteeing the audio has been played. The mechanism you're using to play the audio <em>may</em> have a callback for when the audio actually starts playing though (to help you sync things better).</p> <p>A very common one is</p> <pre><code>[self performSelector:@selector(myMethod:) withObject:someArgumentOrNil afterDelay:3.2]; </code></pre> <p>or you can lookup <code>NSTimer</code> to see how to use that,</p> <p>or the new fangled Grand Central Dispatch version</p> <pre><code>double delayInSeconds = 3.2; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ NSLog(@"later"); }); </code></pre> <p>If your using newer OS and multi-core devices, GCD is a good way to go.</p> <p>If you're using an animation package (cocos2d, for example), they often have timing hooks as well.</p> <hr> <p>Added for expanded question:</p> <p>If all the animations are different, then that's the amount of work you have to do. If they're all the same (or some are the same), you can have an NSTimer call you every .1 (for example) seconds, then test the actual amount of time passed, when you hit the next threshold you trigger the action. (Things aren't guaranteed to run on time - if your app is a CPU hog it could be running late.)</p> <pre><code>if (currentTime &gt;= thresholdTime) { [self doAnim]; thresholdTime = nextOneInLine; } </code></pre> <p>Yes, if it's going to get more complicated, you likely want to build some classes to handle it. Build an array in time order and treat it like a queue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload