Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simplest thing would be to create an ivar BOOL, say _fishIsSwimming, and a _queuedFishView then change the beginning of addFish: to look like this:</p> <pre><code>- (void) addFish:(UIImage *)fish { // queue the most recent fish, if one was passed in if(fish) self.queuedFishView = [[[UIImageView alloc] initWithImage:fish] autorelease]; // If something is swimming, leave now if(_fishIsSwimming) return; // If we get here and there's no queued fish, leave now if(!self.queuedFishView) return; // We have a queued fish and nothing is swimming, so do the queued fish next // and clear the queued fish _fishIsSwimming = YES; self.nextFishView = self.queuedFishView; self.queuedFishView = nil; // Then carry on as normal } </code></pre> <p>Then in your animation completion callback, you do this:</p> <pre><code>-(void) fishSwamOffHandler:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context { // We're done animating, so ready to do another swimming fish _fishIsSwimming = NO; [self.fishViewCurrent removeFromSuperview]; self.fishViewCurrent = self.fishViewNext; self.fishViewNext = nil; // now call to add another fish with nil, so that it will use // the queued fish if there is one and otherwise just early out [self addFish:nil]; } </code></pre> <p>So what will happen is that you'll always maintain the most recently passed in fish in the queuedFishView, and then as soon as the animation is over you can drop back into addFish, and if there's a fish waiting to go then you send it. If not you just wait for the next one sent by a button press</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