简体   繁体   中英

Interrupt completion block based animations to perform separate animations

I am using block based animations to simulate dealing cards as an intro animation for a game. The animation works great unless the user causes a segue to fire DURING the animation, where we perform additional animations in order to get the effect a "sliding" transition from source to destination view controller. What happens now is the cards that have already been "dealt" slide off screen appropriately, and if there are cards that have not been dealt, it deals it in the middle of the transition and then the card disappears when the destination view controller is pushed. It's very ugly.

I have tried 'view.layer removeAllAnimations' which didn't help (I did import quartzcore). What I want to do is cancel the pending animations in the completion blocks, and simply perform the segue animations.

Here's the "dealing" code:

[UIView animateWithDuration:0.20f
                  delay:0.20f
                options:UIViewAnimationOptionCurveEaseOut
             animations:^
{
 _fiveOfHearts.center = CGPointMake(90, 198);
 _fiveOfHearts.transform = fiveOfHeartsTransform;
}

             completion:^(BOOL finished)
{[UIView transitionWithView:_fiveOfHearts duration:0.20f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
     _fiveOfHearts.image = [UIImage imageNamed:@"52"];
 }completion:nil];
 [UIView animateWithDuration:0.30f
                    delay:0.0f
                  options:UIViewAnimationOptionCurveEaseOut
               animations:^
  {
   _jackOfHearts.center = CGPointMake(128, 196);
   _jackOfHearts.transform = jackfHeartsTransform;
  }
               completion:^(BOOL finished)
  {[UIView transitionWithView:_jackOfHearts duration:0.40f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
       _jackOfHearts.image = [UIImage imageNamed:@"112"];
   }completion:nil];
   [UIView animateWithDuration:0.30f
                         delay:0.0f
                       options:UIViewAnimationOptionCurveEaseOut
                    animations:^
    {
        _aceOfHearts.center = CGPointMake(162, 196);
        _aceOfHearts.transform = aceOfHeartsTransform;
    }
                    completion: ... and so on.

The segue code looks something like:

for (UIView *iv in src.view.subviews) {
    if (iv.tag != 99999) {
        [UIView animateWithDuration:0.5f animations:^{iv.center = CGPointMake(iv.center.x - 600, iv.center.y);}];
    }
}

You could add a global BOOL say hasUserSkippedOn once the user presses to move on set it to YES and then every time you hit a completion block check if _hasUserSkipped is still YES then do not proform any more. Normally on blocks it has a default end bool but I am not too sure if animations blocks have the end bool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM