1

I have a custom dismiss animation that uses UIPercentDrivenInteractiveTransition and UIViewControllerAnimatedTransitioning. It is initiated by an unwind segue and the transitioning delegate is set up in prepareForSegue:.

In my presenting view controller, the unwind IBAction keeps getting called as soon as I begin the segue, instead of when the segue is completed. This is problematic since my dismiss animation is gesture driven, so we do not know how long it will take to complete.

Is there a way to know when the segue has completed its animation?

Neither viewWillAppear: nor viewDidAppear: seem to get called at the moment of completion, I assume this is because the segue is an unwind segue.

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82

2 Answers2

0

catching animation when completed you can use this.

- (void)perform {
      [CATransaction begin];
        [[self sourceViewController] presentViewController:[self destinationViewController] animated:YES completion:nil];
      [CATransaction setCompletionBlock:^{
            //whatever you want to do after the animation
      }];
      [CATransaction commit];
    }
Rai
  • 187
  • 2
  • 15
0

This is explained in UIStoryboardSegue.h:

/// Subclasses can override this method to augment or replace the effect of this segue. For example, to animate alongside the effect of a Modal Presentation segue, an override of this method can call super, then send -animateAlongsideTransition:completion: to the transitionCoordinator of the destinationViewController.
/// The segue runtime will call +[UIView setAnimationsAreEnabled:] prior to invoking this method, based on the value of the Animates checkbox in the Properties Inspector for the segue.
- (void)perform;

e.g.

- (void)perform{

    [self.destinationViewController.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {

    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        // unwind segue animation has completed
    }];

    [super perform];

}
malhal
  • 26,330
  • 7
  • 115
  • 133