Custom UIViewController Transitions

Custom UIViewController Transitions

Short show and tell talking about adding custom UIViewController transitions to an iOS app.

My code sample can be found on GitHub:

Apple Links:


Mike Zornek

January 08, 2015


  1. Custom UIViewController Transitions Mike Zornek • January 8, 2015

  2. More Info • WWDC 2013 Session 218 • Sample Code: • My Demo: CustomViewControllerTransitionsDemo
  3. Transitions are found inside… • Presentation
 presentViewController:animated:completion: • UINavigationController •

    UITabBarController • UICollectionViewController
  4. A B .modalPresentationStyle .modalTransitionStyle

  5. .modalPresentationStyle The presentation style determines how a modally presented view

    controller is displayed onscreen. In a horizontally compact environment, modal view controllers are always presented full-screen. In a horizontally regular environment, there are several different presentation options. For a list of possible presentation styles, and their compatibility with the available transition styles, see the Modal Presentation Styles constant descriptions.
  6. None
  7. .modalTransitionStyle This property determines how the view controller's is animated

    onscreen when it is presented using the presentViewController:animated:completion: method. To change the transition type, you must set this property before presenting the view controller. The default value for this property is UIModalTransitionStyleCoverVertical. Others include: • UIModalTransitionStyleFlipHorizontal • UIModalTransitionStyleCrossDissolve • UIModalTransitionStylePartialCurl
  8. Doing it custom…

  9. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"launchModal"]) { UIViewController

    *vc = segue.destinationViewController; vc.modalPresentationStyle = UIModalPresentationCustom; vc.transitioningDelegate = self; } }
  10. @protocol UIViewControllerTransitioningDelegate <NSObject> @optional - (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController

    *)presenting sourceController:(UIViewController *)source; - (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; // 2 more for interaction, 1 more for presentation controller @end
  11. #pragma mark - UIViewControllerTransitioningDelegate - (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController

    *)presenting sourceController:(UIViewController *)source { GrowAndFadeTransitionAnimator *animator = [[GrowAndFadeTransitionAnimator alloc] init]; animator.appearing = YES; return animator; } - (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed;{ GrowAndFadeTransitionAnimator *animator = [[GrowAndFadeTransitionAnimator alloc] init]; animator.appearing = NO; return animator; }
  12. @protocol UIViewControllerAnimatedTransitioning <NSObject> - (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext; - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext; @optional

    - (void)animationEnded:(BOOL) transitionCompleted; @end
  13. Demo