Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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. More Info • WWDC 2013 Session 218 • Sample Code:


    https://github.com/soleares/SOLPresentingFun • My Demo:
 https://github.com/zorn/ CustomViewControllerTransitionsDemo
  2. .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.
  3. .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
  4. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"launchModal"]) { UIViewController

    *vc = segue.destinationViewController; vc.modalPresentationStyle = UIModalPresentationCustom; vc.transitioningDelegate = self; } }
  5. @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
  6. #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; }