Slide 1

Slide 1 text

Custom UIViewController Transitions Mike Zornek • January 8, 2015

Slide 2

Slide 2 text

More Info • WWDC 2013 Session 218 • Sample Code:
 https://github.com/soleares/SOLPresentingFun • My Demo:
 https://github.com/zorn/ CustomViewControllerTransitionsDemo

Slide 3

Slide 3 text

Transitions are found inside… • Presentation
 presentViewController:animated:completion: • UINavigationController • UITabBarController • UICollectionViewController

Slide 4

Slide 4 text

A B .modalPresentationStyle .modalTransitionStyle

Slide 5

Slide 5 text

.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.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

.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

Slide 8

Slide 8 text

Doing it custom…

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

@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

Slide 11

Slide 11 text

#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; }

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Demo