$30 off During Our Annual Pro Sale. View Details »

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:

https://github.com/zorn/CustomViewControllerTransitionsDemo

Apple Links:

https://developer.apple.com/videos/wwdc/2013/

https://github.com/soleares/SOLPresentingFun

Mike Zornek

January 08, 2015
Tweet

More Decks by Mike Zornek

Other Decks in Programming

Transcript

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

    View Slide

  2. More Info
    • WWDC 2013 Session 218
    • Sample Code:

    https://github.com/soleares/SOLPresentingFun
    • My Demo:

    https://github.com/zorn/
    CustomViewControllerTransitionsDemo

    View Slide

  3. Transitions are found inside…
    • Presentation

    presentViewController:animated:completion:
    • UINavigationController
    • UITabBarController
    • UICollectionViewController

    View Slide

  4. A B
    .modalPresentationStyle
    .modalTransitionStyle

    View Slide

  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.

    View Slide

  6. View Slide

  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

    View Slide

  8. Doing it custom…

    View Slide

  9. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"launchModal"]) {
    UIViewController *vc = segue.destinationViewController;
    vc.modalPresentationStyle = UIModalPresentationCustom;
    vc.transitioningDelegate = self;
    }
    }

    View Slide

  10. @protocol UIViewControllerTransitioningDelegate
    @optional
    - (id )
    animationControllerForPresentedController:(UIViewController *)presented
    presentingController:(UIViewController *)presenting
    sourceController:(UIViewController *)source;
    - (id )
    animationControllerForDismissedController:(UIViewController *)dismissed;
    // 2 more for interaction, 1 more for presentation controller
    @end

    View Slide

  11. #pragma mark - UIViewControllerTransitioningDelegate
    - (id )
    animationControllerForPresentedController:(UIViewController *)presented
    presentingController:(UIViewController *)presenting
    sourceController:(UIViewController *)source
    {
    GrowAndFadeTransitionAnimator *animator = [[GrowAndFadeTransitionAnimator alloc] init];
    animator.appearing = YES;
    return animator;
    }
    - (id )
    animationControllerForDismissedController:(UIViewController *)dismissed;{
    GrowAndFadeTransitionAnimator *animator = [[GrowAndFadeTransitionAnimator alloc] init];
    animator.appearing = NO;
    return animator;
    }

    View Slide

  12. @protocol UIViewControllerAnimatedTransitioning
    - (NSTimeInterval)transitionDuration:(id )transitionContext;
    - (void)animateTransition:(id )transitionContext;
    @optional
    - (void)animationEnded:(BOOL) transitionCompleted;
    @end

    View Slide

  13. Demo

    View Slide