218.pdf

231
These are confidential sessions—please refrain from streaming, blogging, or taking pictures New capabilities, APIs and enhancements Session 218 Custom Transitions Using View Controllers Bruce D. Nilo View Controller Mechanic

Upload: anonymous-egfm5r

Post on 16-Aug-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

These are confidential sessionsplease refrain from streaming, blogging, or taking picturesNew capabilities, APIs and enhancementsSession 218Custom Transitions Using View ControllersBruce D. NiloView Controller MechanicRoadmapRoadmap New animation tools Custom view controller transitions Interactive view controller transitions Canceling and coordinating transitionsNew animation toolsRoadmapNew animation toolsRoadmap Quick review of the block based UIView animation APINew animation toolsRoadmap Quick review of the block based UIView animation API Spring animationsNew animation toolsRoadmap Quick review of the block based UIView animation API Spring animations Key-frame animationsNew animation toolsRoadmap Quick review of the block based UIView animation API Spring animations Key-frame animations UIKit DynamicsCustom view controller transitionsRoadmapCustom view controller transitionsRoadmap Which transitions can be customized?!Presentations and dismissals!UITabBarController!UINavigationController!UICollectionViewController layout-to-layout transitionsCustom view controller transitionsRoadmap Which transitions can be customized?!Presentations and dismissals!UITabBarController!UINavigationController!UICollectionViewController layout-to-layout transitions What is a transition?!Anatomy and generalizationsCustom view controller transitionsRoadmap Which transitions can be customized?!Presentations and dismissals!UITabBarController!UINavigationController!UICollectionViewController layout-to-layout transitions What is a transition?!Anatomy and generalizations API discussion with some examplesInteractive view controller transitionsRoadmapInteractive view controller transitionsRoadmap Adding interactivity to custom transitionsInteractive view controller transitionsRoadmap Adding interactivity to custom transitions Special support for UICollectionViews!UICollectionViewTransitionLayoutInteractive view controller transitionsRoadmap Adding interactivity to custom transitions Special support for UICollectionViews!UICollectionViewTransitionLayout Canceling transitionsInteractive view controller transitionsRoadmap Adding interactivity to custom transitions Special support for UICollectionViews!UICollectionViewTransitionLayout Canceling transitions UITransitionCoordinator!Animating alongside transitions!Specifying a completion handler!This can be used for all UINavigationController transitions!Create compelling, custom, view controller transitionsNew UIView Animation APIsQuick review: Existing UIView block based APINew UIView Animation APIsQuick review: Existing UIView block based APINew UIView Animation APIs+ (void) beginAnimations:context:+ (void) commitAnimationsQuick review: Existing UIView block based APINew UIView Animation APIs+ (void) beginAnimations:context:+ (void) commitAnimations+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;} completion: nil];New UIView Animation APIsQuick review: Relationship to core animation[UIView animationWithDuration:delay:options:animations:^{Relationship to core animation[UIView animationWithDuration:...animations:^{} completion: nil];New UIView Animation APIsQuick review: Relationship to core animation[UIView animationWithDuration:delay:options:animations:^{Relationship to core animation[UIView animationWithDuration:...animations:^{} completion: nil];New UIView Animation APIsQuick review: Relationship to core animationUIViewUIViewUIViewUIView[UIView animationWithDuration:delay:options:animations:^{Relationship to core animation[UIView animationWithDuration:...animations:^{} completion: nil];UIViewUIViewUIViewCALayerNew UIView Animation APIsQuick review: Relationship to core animationUIViewUIViewUIViewUIView[UIView animationWithDuration:delay:options:animations:^{Update propertiesRelationship to core animation[UIView animationWithDuration:...animations:^{[UIView animationWithDuration:delay:options:animations:^{Quick review: Relationship to core animationUIViewUIViewUIViewNew UIView Animation APIsRelationship to core animationUIViewUIViewUIViewUIView[UIView animationWithDuration:...animations:^{} completion: nil];Update propertiesCALayer[UIView animationWithDuration:delay:options:animations:^{Quick review: Relationship to core animationUIViewUIViewUIViewNew UIView Animation APIsRelationship to core animationUIViewUIViewUIViewUIView[UIView animationWithDuration:...animations:^{} completion: nil];Update propertiesCALayerCAAnimationsadded to layersUIView block based APINew UIView Animation APIs Disabling and enabling animations+ (void)setAnimationsEnabled:(BOOL)UIView block based APINew UIView Animation APIs+ (void)performWithoutAnimation:(void ^(void))actions;UIView block based APINew UIView Animation APIs+ (void)performWithoutAnimation:(void ^(void))actions;Spring animationsNew UIView Animation APIsSpring animationsNew UIView Animation APIs Two new parameters!DampingRatio!1.0 >= r > 0.0!Initial Spring Velocity Composes nicely with other UIView animation methodsSpring animationsNew UIView Animation APIs+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;Spring animationsNew UIView Animation APIs+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;Key-frame animationsNew UIView Animation APIsKey-frame animationsNew UIView Animation APIs animateKeyframesWithDuration!is to CAKeyframeAnimation Key-frame animationsNew UIView Animation APIs animateKeyframesWithDuration!is to CAKeyframeAnimation as animateWithDuration!is to CABasicAnimationKey-frame animationsNew UIView Animation APIs animateKeyframesWithDuration!is to CAKeyframeAnimation as animateWithDuration!is to CABasicAnimation Specify keyframes within the animation block!Options augmented to include calculation modeKey-frame animationsNew UIView Animation APIs animateKeyframesWithDuration!is to CAKeyframeAnimation as animateWithDuration!is to CABasicAnimation Specify keyframes within the animation block!Options augmented to include calculation mode Composes nicely with other UIView animation methodsKey-frame animationsNew View Based Animation APIs+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)addKeyframeWithRelativeStartTime:(double)frameStartTimerelativeDuration:(double)frameDurationanimations:(void (^)(void))animationsKey-frame animationsNew View Based Animation APIs+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)addKeyframeWithRelativeStartTime:(double)frameStartTimerelativeDuration:(double)frameDurationanimations:(void (^)(void))animationsKey-frame animationsNew View Based Animation APIs+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)addKeyframeWithRelativeStartTime:(double)frameStartTimerelativeDuration:(double)frameDurationanimations:(void (^)(void))animationsKey-frame animationsNew View Based Animation APIs[UIView animateKeyframesWithDuration: .35delay: 0.0options:0animations:^{[UIView addKeyframe animations: ^{}];[UIView addKeyframe animations:^{}];[UIView addKeyframe animations:^{[someView setPosition:];// etc.}];}completion:^(BOOL finished) {}];Key-frame animationsNew View Based Animation APIs[UIView animateKeyframesWithDuration: .35delay: 0.0options:0animations:^{[UIView addKeyframe animations: ^{}];[UIView addKeyframe animations:^{}];[UIView addKeyframe animations:^{[someView setPosition:];// etc.}];}completion:^(BOOL finished) {}];Key-frame animationsNew View Based Animation APIs[UIView animateKeyframesWithDuration: .35delay: 0.0options:0animations:^{[UIView addKeyframe animations: ^{}];[UIView addKeyframe animations:^{}];[UIView addKeyframe animations:^{[someView setPosition:];// etc.}];}completion:^(BOOL finished) {}];UIView snapshotsImproved and Simplified Snapshot APIUIView snapshotsImproved and Simplified Snapshot APISnapshot API- (UIView *)[UIView snapshotView]- (UIView *)[UIView resizableSnapshotViewFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsetsUIView snapshotsImproved and Simplified Snapshot APISnapshot API- (UIView *)[UIView snapshotView]- (UIView *)[UIView resizableSnapshotViewFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsetsCreating snapshots from snapshots is supportedUIKit DynamicsNew View Based Animation APIsUIKit DynamicsNew View Based Animation APIs Distinct from UIView animation APIsUIKit DynamicsNew View Based Animation APIs Distinct from UIView animation APIs!Compatible with the new transitioning APIs!More in this afternoons talkIts easy to useCustomizing Your View Controller TransitionsWhich transitions can be customized?Custom View Controller TransitionsWhich transitions can be customized?Custom View Controller Transitions Presentations and dismissals!Supported presentation styles!UIModalPresentationFullScreen!UIModalPresentationCustomWhich transitions can be customized?Custom View Controller Transitions Presentations and dismissals!Supported presentation styles!UIModalPresentationFullScreen!UIModalPresentationCustomThe from view controller is not removed from the window hierarchyUIViewController *vc = ;id transitioningDelegate;vc.modalPresentationStyle = UIModalPresentationCustom;[vc setTransitioningDelegate: transitioningDelegate];[self presentViewController:vc animated: YES completion: nil];Which transitions can be customized?Custom View Controller Transitions Presentations and dismissals!Supported presentation styles!UIModalPresentationFullScreen!UIModalPresentationCustomThe from view controller is not removed from the window hierarchyUIViewController *vc = ;id transitioningDelegate;vc.modalPresentationStyle = UIModalPresentationCustom;[vc setTransitioningDelegate: transitioningDelegate];[self presentViewController:vc animated: YES completion: nil];Which transitions can be customized?Custom View Controller Transitions Presentations and dismissals!Supported presentation styles!UIModalPresentationFullScreen!UIModalPresentationCustomThe from view controller is not removed from the window hierarchyWhich transitions can be customized?Custom View Controller TransitionsWhich transitions can be customized?Custom View Controller Transitions UITabBarController setSelectedViewController:(UIViewController *)vc;setSelectedIndex:(NSUInteger)idx;Which transitions can be customized?Custom View Controller Transitions UITabBarController setSelectedViewController:(UIViewController *)vc;setSelectedIndex:(NSUInteger)idx;NSUInteger secondTab = 1;self.delegate = tabBarControllerDelegate;[self setSelectedIndex:secondTab];Which transitions can be customized?Custom View Controller TransitionsWhich transitions can be customized?Custom View Controller Transitions UINavigationController pushViewController:animated:popViewControllerAnimated:setViewControllers:animated:Which transitions can be customized?Custom View Controller Transitions UINavigationController pushViewController:animated:popViewControllerAnimated:setViewControllers:animated:self.delegate = navigationControllerDelegate;[self pushViewController:vc animated:YES];UINavigationController meets UICollectionViewControllerCustom View Controller TransitionsUINavigationController meets UICollectionViewControllerCustom View Controller Transitions Layout-to-layout navigation transitionsUINavigationController meets UICollectionViewControllerCustom View Controller Transitions Layout-to-layout navigation transitionsUICollectionViewLayout *layout1,*layout2,*layout3;UICollectionViewController *cvc1, *cvc2, *cvc3;cvc1 = [cvc1 initWithCollectionViewLayout:layout1];[nav pushViewController:cvc1 animated:YES]cvc2.useLayoutToLayoutNavigationTransitions = YES;cvc3.useLayoutToLayoutNavigationTransitions = YES;[nav pushViewController:cvc2 animated:YES];[nav pushViewController:cvc3 animated:YES];[nav popViewControllerAnimated:YES];DemoSome examples of custom transitionsConcepts and APIsCustomizing Your View Controller TransitionsThe anatomy of a transitionCustom View Controller TransitionsChild AParent VCChild AParent ViewViewChild AParent VCParent ViewChild A ViewChild BChild BWindow WindowStart State End StateLegendVC-ViewContainmentSuperviewRelationships:Objects:View ControllerViewThe anatomy of a transitionCustom View Controller TransitionsParent VCParent ViewChild AViewChild BChild BWindowIntermediate StateChild AContainer ViewChild AThe anatomy of a transitionCustom View Controller TransitionsIntermediate StateChild AParent VCViewChild BWindowChild BContainer ViewChild AThe anatomy of a transitionCustom View Controller TransitionsIntermediate StateChild AParent VCViewChild BWindowChild B Child AContainer ViewChild AThe anatomy of a transitionCustom View Controller TransitionsIntermediate StateChild AParent VCViewChild BWindowChild BContainer ViewChild AThe anatomy of a transitionCustom View Controller TransitionsIntermediate StateChild AParent VCViewChild BWindowChild B Child BThe anatomy of a transitionCustom View Controller TransitionsChild AParent VCParent ViewChild A ViewChild BChild BWindowEnd StateThe anatomy of a transitionCustom View Controller TransitionsThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchyThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commencesThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc.The anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc. Container view, and start and final view positions are computedThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc. Container view, and start and final view positions are computed Optional animation to end state view hierarchy is runThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc. Container view, and start and final view positions are computed Optional animation to end state view hierarchy is run Animation completes!Internal structures are updated, callbacks made, etc.The anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc. Container view, and start and final view positions are computed Optional animation to end state view hierarchy is run Animation completes!Internal structures are updated, callbacks made, etc. End State!Consistent view controller hierarchy and view hierarchyThe anatomy of a transitionCustom View Controller Transitions Start state !Consistent view controller hierarchy and view hierarchy User or programmatic transition commences Internal structures are updated, callbacks made, etc. Container view, and start and final view positions are computed Optional animation to end state view hierarchy is run Animation completes!Internal structures are updated, callbacks made, etc. End State!Consistent view controller hierarchy and view hierarchy

Custom View Controller Transitions@protocol UIViewControllerContextTransitioning // The view in which the animated transition should take place.- (UIView *)containerView;// Two keys for themethod below are currently defined by the system // UITransitionContextToViewControllerKey, and UITransitionContextFromViewControllerKey. - (UIViewController *) viewControllerForKey:(NSString *)key;- (CGRect) initialFrameForViewController:(UIViewController *)vc;- (CGRect) finalFrameForViewController:(UIViewController *)vc;// This MUST be called whenever a transition completes (or is cancelled.)- (void)completeTransition:(BOOL)didComplete;...@end

Custom View Controller Transitions@protocol UIViewControllerContextTransitioning // The view in which the animated transition should take place.- (UIView *)containerView;// Two keys for themethod below are currently defined by the system // UITransitionContextToViewControllerKey, and UITransitionContextFromViewControllerKey. - (UIViewController *) viewControllerForKey:(NSString *)key;- (CGRect) initialFrameForViewController:(UIViewController *)vc;- (CGRect) finalFrameForViewController:(UIViewController *)vc;// This MUST be called whenever a transition completes (or is cancelled.)- (void)completeTransition:(BOOL)didComplete;...@end

Custom View Controller Transitions@protocol UIViewControllerContextTransitioning // The view in which the animated transition should take place.- (UIView *)containerView;// Two keys for themethod below are currently defined by the system // UITransitionContextToViewControllerKey, and UITransitionContextFromViewControllerKey. - (UIViewController *) viewControllerForKey:(NSString *)key;- (CGRect) initialFrameForViewController:(UIViewController *)vc;- (CGRect) finalFrameForViewController:(UIViewController *)vc;// This MUST be called whenever a transition completes (or is cancelled.)- (void)completeTransition:(BOOL)didComplete;...@end

Custom View Controller Transitions@protocol UIViewControllerContextTransitioning // The view in which the animated transition should take place.- (UIView *)containerView;// Two keys for themethod below are currently defined by the system // UITransitionContextToViewControllerKey, and UITransitionContextFromViewControllerKey. - (UIViewController *) viewControllerForKey:(NSString *)key;- (CGRect) initialFrameForViewController:(UIViewController *)vc;- (CGRect) finalFrameForViewController:(UIViewController *)vc;// This MUST be called whenever a transition completes (or is cancelled.)- (void)completeTransition:(BOOL)didComplete;...@end

Custom View Controller Transitions@protocol UIViewControllerAnimatedTransitioning - (NSTimeInterval)transitionDuration:(id )ctx;// This method can onlybe a nop if the transition is interactive and not a percentDriven interactive transition.- (void)animateTransition:(id )ctx;@optional// This is a convenience and if implemented will be invoked by the system when the transition context's completeTransition: method is invoked.- (void)animationEnded:(BOOL) transitionCompleted;@end

Custom View Controller Transitions@protocol UIViewControllerAnimatedTransitioning - (NSTimeInterval)transitionDuration:(id )ctx;// This method can onlybe a nop if the transition is interactive and not a percentDriven interactive transition.- (void)animateTransition:(id )ctx;@optional// This is a convenience and if implemented will be invoked by the system when the transition context's completeTransition: method is invoked.- (void)animationEnded:(BOOL) transitionCompleted;@end

Custom View Controller Transitions@protocol UIViewControllerAnimatedTransitioning - (NSTimeInterval)transitionDuration:(id )ctx;// This method can onlybe a nop if the transition is interactive and not a percentDriven interactive transition.- (void)animateTransition:(id )ctx;@optional// This is a convenience and if implemented will be invoked by the system when the transition context's completeTransition: method is invoked.- (void)animationEnded:(BOOL) transitionCompleted;@endChild AParent VCViewChild BWindowThe anatomy of a transitionCustom View Controller TransitionsParent ViewChild AChild BChild AParent VCViewChild BWindowThe anatomy of a transitionCustom View Controller Transitions(id ) context;[animationController animateTransition: context];Parent ViewChild AChild BChild AParent VCViewChild BWindowThe anatomy of a transitionCustom View Controller Transitions(id ) context;[animationController animateTransition: context];Parent ViewChild AChild B Child BChild AParent VCViewChild BWindowThe anatomy of a transitionCustom View Controller Transitions(id ) context;[context completeTransition: YES];Parent ViewChild AChild B Child BThe anatomy of a transitionCustom View Controller TransitionsChild AParent VCParent ViewChild A ViewChild BChild BWindowWiring it all togetherCustom View Controller TransitionsWiring it all togetherCustom View Controller Transitions Animation and interaction controllers are vended by delegates

Wiring it all togetherCustom View Controller Transitions Animation and interaction controllers are vended by delegates

Animation controllers conform to a protocol

Wiring it all togetherCustom View Controller Transitions Animation and interaction controllers are vended by delegates

Animation controllers conform to a protocol

Interaction controllers conform to a protocol

Wiring it all togetherCustom View Controller Transitions Animation and interaction controllers are vended by delegates

Animation controllers conform to a protocol

Interaction controllers conform to a protocol

A system object passed to the controllers conforms to

Start of a custom presentationCustom View Controller TransitionsPresented ControllerPresenting ControllertransitionDelegateStart of a custom presentationCustom View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllertransitionDelegateStart of a custom presentationCustom View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllerPresented ControllerpresentViewController:transitionDelegateStart of a custom presentationCustom View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllerPresented ControllerpresentViewController:transitionDelegateanimationControllerForPresentingController:presentedController:sourceController:

(animationController)End of a custom presentationCustom View Controller TransitionsanimationControlleranimationControllercontextEnd of a custom presentationCustom View Controller TransitionsanimationController

(context)transitionDuration:animationControllercontextEnd of a custom presentationCustom View Controller TransitionsanimationController

(context)transitionDuration:animationController

(context)animateTransition:contextEnd of a custom presentationCustom View Controller TransitionsanimationController

(context)transitionDuration:animationController

(context)animateTransition:context animationController completeTransition:Pseudo-code of a custom presentation Custom View Controller Transitionsid delegate;[presentedController setTransitioningDelegate:delegate];[presentedController setModalPresentationStyle: UIModalPresentationCustom];[self presentViewController:presentedController animated: YES completion:nil];Pseudo-code of a custom presentation Custom View Controller Transitionsid delegate;[presentedController setTransitioningDelegate:delegate];[presentedController setModalPresentationStyle: UIModalPresentationCustom];[self presentViewController:presentedController animated: YES completion:nil];Pseudo-code of a custom presentation Custom View Controller Transitionsid animationController = [delegate animationControllerForPresentedController: presented presentingController: presenter sourceController: target];id )ctx;NSTimeInterval duration =[animationController transitionDuration:ctx];[animationController animateTransition:ctx];Pseudo-code of a custom presentation Custom View Controller Transitionsid )ctx;NSTimeInterval duration =[animationController transitionDuration:ctx];[animationController animateTransition:ctx];Pseudo-code of a custom presentation Custom View Controller Transitions- (void)animateTransition:(id ctx {UIView *inView = [ctx containerView];UIView *toView = [[ctx viewControllerForKey:]view];UIView *fromView = [[ctx viewControllerForKey: ];CGSize size = toEndFrame.size;

if(self.isPresentation) { [inView addSubview: toView];}else { [inView insertSubview:toView belowSubview: [fromVC view]];}[UIView animateWithDuration: self.transitionDuration animations: ^ {if(self.isPresentation) {toView.center = newCenter;toView.bounds = newBounds;}else {} completion: ^(BOOL finished) { [ctx completeTransition: YES];}];}Pseudo-code of a custom presentation Custom View Controller Transitions- (void)animateTransition:(id ctx {UIView *inView = [ctx containerView];UIView *toView = [[ctx viewControllerForKey:]view];UIView *fromView = [[ctx viewControllerForKey: ];CGSize size = toEndFrame.size;

if(self.isPresentation) { [inView addSubview: toView];}else { [inView insertSubview:toView belowSubview: [fromVC view]];}[UIView animateWithDuration: self.transitionDuration animations: ^ {if(self.isPresentation) {toView.center = newCenter;toView.bounds = newBounds;}else {} completion: ^(BOOL finished) { [ctx completeTransition: YES];}];}Pseudo-code of a custom presentation Custom View Controller Transitions- (void)animateTransition:(id ctx {UIView *inView = [ctx containerView];UIView *toView = [[ctx viewControllerForKey:]view];UIView *fromView = [[ctx viewControllerForKey: ];CGSize size = toEndFrame.size;

if(self.isPresentation) { [inView addSubview: toView];}else { [inView insertSubview:toView belowSubview: [fromVC view]];}[UIView animateWithDuration: self.transitionDuration animations: ^ {if(self.isPresentation) {toView.center = newCenter;toView.bounds = newBounds;}else {} completion: ^(BOOL finished) { [ctx completeTransition: YES];}];}Pseudo-code of a custom presentation Custom View Controller Transitionsid )ctx;[ctx completeTransition:YES];Pseudo-code of a custom presentation Custom View Controller TransitionsUIViewControllerTransitioningDelegateCustom View Controller Transitions@protocol UIViewControllerTransitioningDelegate @optional- (id ) animationControllerForPresentedController:(UIVC *)presented presentingController:(UIVC *)presenting sourceController:(UIVC *)source;- (id )animationControllerForDismissedController:(UIVC *)dismissed;- (id )interactionControllerForPresentation:(id )a;- (id )interactionControllerForDismissal:(id )a;@endUIViewControllerTransitioningDelegateCustom View Controller Transitions@protocol UIViewControllerTransitioningDelegate @optional- (id ) animationControllerForPresentedController:(UIVC *)presented presentingController:(UIVC *)presenting sourceController:(UIVC *)source;- (id )animationControllerForDismissedController:(UIVC *)dismissed;- (id )interactionControllerForPresentation:(id )a;- (id )interactionControllerForDismissal:(id )a;@endUIViewControllerTransitioningDelegateCustom View Controller Transitions@protocol UIViewControllerTransitioningDelegate @optional- (id ) animationControllerForPresentedController:(UIVC *)presented presentingController:(UIVC *)presenting sourceController:(UIVC *)source;- (id )animationControllerForDismissedController:(UIVC *)dismissed;- (id )interactionControllerForPresentation:(id )a;- (id )interactionControllerForDismissal:(id )a;@end@interface UIViewController(CustomTransitioning)@property (nonatomic,retain) id transitionDelegate;@endUIViewControllerTransitioningDelegateCustom View Controller Transitions@interface UIViewController(CustomTransitioning)@property (nonatomic,retain) id transitionDelegate;@endUIViewControllerTransitioningDelegateCustom View Controller TransitionsUINavigationControllerDelegate ExtensionsCustom View Controller Transitions- (id )navigationController:(UINC *)nc animationControllerForOperation: (UINavigationControllerOperation)op fromViewController:(UIViewController *)fromVCtoViewController:(UIViewController *)toVC;- (id )navigationController: (UINC *)nc interactionControllerForAnimationController: (id )a;UITabBarControllerDelegate ExtensionsCustom View Controller Transitions- (id )tabBarController: (UITABC *)tbcanimationControllerForTransitionFromViewController:(UIVC *)fromVC toViewController:(UIVC *)toVC;- (id )tabBarController: (UITABC *)tbc interactionControllerForAnimationController: (id )a;Responsibilities of the animation controllerCustom View Controller TransitionsResponsibilities of the animation controllerCustom View Controller Transitions Implementation of animateTransition: and transitionDuration:!Insertion of to view controllers view into the container viewResponsibilities of the animation controllerCustom View Controller Transitions Implementation of animateTransition: and transitionDuration:!Insertion of to view controllers view into the container view When the transition animation completes!The to and from view controllers views need to be in their designated positions!The contexts completeTransition: method must be invokedIntroductionInteractive View Controller TransitionsRunning transition animations interactivelyInteractive View Controller Transitions UINavigationController!Interactive pop gesture is pervasive on iOS 7.0Running transition animations interactivelyInteractive View Controller Transitions UINavigationController!Interactive pop gesture is pervasive on iOS 7.0 Applications can define their own interactive transitionsRunning transition animations interactivelyInteractive View Controller Transitions UINavigationController!Interactive pop gesture is pervasive on iOS 7.0 Applications can define their own interactive transitions!Interactive transitions need not be gesture drivenRunning transition animations interactivelyInteractive View Controller Transitions UINavigationController!Interactive pop gesture is pervasive on iOS 7.0 Applications can define their own interactive transitions!Interactive transitions need not be gesture driven!Interactive transitions usually run forwards and backwards!Often a transition can start and be cancelledRunning transition animations interactivelyInteractive View Controller Transitions UINavigationController!Interactive pop gesture is pervasive on iOS 7.0 Applications can define their own interactive transitions!Interactive transitions need not be gesture driven!Interactive transitions usually run forwards and backwards!Often a transition can start and be cancelled UIKit provides a concrete interaction controller class!UIPercentDrivenInteractiveTransition

Interactive View Controller Transitions@protocol UIViewControllerInteractiveTransitioning - (void)startInteractiveTransition:(id )ctx;@optional- (CGFloat)completionSpeed;- (UIViewAnimationCurve)completionCurve;@end

Interactive View Controller Transitions@protocol UIViewControllerInteractiveTransitioning - (void)startInteractiveTransition:(id )ctx;@optional- (CGFloat)completionSpeed;- (UIViewAnimationCurve)completionCurve;@endStart of an interactive presentationInteractive View Controller TransitionsPresented ControllerPresenting ControllertransitionDelegateStart of an interactive presentationInteractive View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllertransitionDelegateStart of an interactive presentationInteractive View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllerPresented ControllerpresentViewController:transitionDelegateStart of an interactive presentationInteractive View Controller TransitionsPresented Controller

(transitionDelegate)setTransitioningDelegate:Presenting ControllerPresented ControllerpresentViewController:transitionDelegateanimationControllerForPresentingController:presentedController:sourceController:

(animationController)

(interactionController)interactionControllerForPresentation:Interactive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorfinishInteractiveTransitionStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsInteractive Event HandlerUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteAnimatorInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingContext InteractorStatesAgentsThe easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions The easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions Implement the animation controller!animatePresentation: must be implemented using the UIView animation block APIsThe easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions Implement the animation controller!animatePresentation: must be implemented using the UIView animation block APIs Implement the logic that will drive the interaction!e.g. The target of a gesture recognizer!Often this target is a subclass of UIViewControllerPercentDrivenTransitionThe easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions Implement the animation controller!animatePresentation: must be implemented using the UIView animation block APIs Implement the logic that will drive the interaction!e.g. The target of a gesture recognizer!Often this target is a subclass of UIViewControllerPercentDrivenTransition!The interaction logic will call!updateInteractiveTransition:(CGFloat)percent!completeInteractiveTransition or cancelInteractiveTransition!(Note that startInteractiveTransition is handled automatically)UIPercentDrivenInteractiveTransitionInteractive View Controller Transitions// The associated animation controller must animate its transition using UIView animation APIs. @interface UIPercentDrivenInteractiveTransition : NSObject @property (readonly) CGFloat duration;// The last percentComplete value specified by updateInteractiveTransition:@property (readonly) CGFloat percentComplete;// completionSpeed defaults to 1.0 which corresponds to a completion duration of// (1 - percentComplete)*duration.It must be greater than 0.0.@property (nonatomic,assign) CGFloat completionSpeed;// When the interactive part of the transition has completed, this property can// be set to indicate a different animation curve.@property (nonatomic,assign) UIViewAnimationCurve completionCurve;// Used instead of the corresponding context methods.- (void)updateInteractiveTransition:(CGFloat)percentComplete;- (void)cancelInteractiveTransition;- (void)finishInteractiveTransition;@endUIPercentDrivenInteractiveTransitionInteractive View Controller Transitions// The associated animation controller must animate its transition using UIView animation APIs. @interface UIPercentDrivenInteractiveTransition : NSObject @property (readonly) CGFloat duration;// The last percentComplete value specified by updateInteractiveTransition:@property (readonly) CGFloat percentComplete;// completionSpeed defaults to 1.0 which corresponds to a completion duration of// (1 - percentComplete)*duration.It must be greater than 0.0.@property (nonatomic,assign) CGFloat completionSpeed;// When the interactive part of the transition has completed, this property can// be set to indicate a different animation curve.@property (nonatomic,assign) UIViewAnimationCurve completionCurve;// Used instead of the corresponding context methods.- (void)updateInteractiveTransition:(CGFloat)percentComplete;- (void)cancelInteractiveTransition;- (void)finishInteractiveTransition;@endThe easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions The easy wayuse UIViewControllerPercentDrivenTransitionInteractive View Controller Transitions UIPercentDrivenInteractiveTransitionInteractive View Controller Transitions@interface YYSlideInteractor : UIPercentDrivenInteractiveTransition - (instancetype)initWithNavigationController:(UINavigationController *)nc;@property(nonatomic,assign) UINavigationController *parent;@property(nonatomic,assign,getter = isInteractive) BOOL interactive;@endUIPercentDrivenInteractiveTransitionInteractive View Controller Transitions- (void)handlePinch:(UIPinchGestureRecognizer *)gr {CGFloat scale = [gr scale];switch ([gr state]) {case UIGestureRecognizerStateBegan:self.interactive = YES; _startScale = scale;[self.parent popViewControllerAnimated:YES];break;case UIGestureRecognizerStateChanged: {CGFloat percent = (1.0 - scale/_startScale);[self updateInteractiveTransition: (percent = 0.0 || [gr state] == UIGestureRecognizerStateCancelled) [self cancelInteractiveTransition];else[self finishInteractiveTransition];self.interactive = NO;break;}}UIPercentDrivenInteractiveTransitionInteractive View Controller Transitions- (void)handlePinch:(UIPinchGestureRecognizer *)gr {CGFloat scale = [gr scale];switch ([gr state]) {case UIGestureRecognizerStateBegan:self.interactive = YES; _startScale = scale;[self.parent popViewControllerAnimated:YES];break;case UIGestureRecognizerStateChanged: {CGFloat percent = (1.0 - scale/_startScale);[self updateInteractiveTransition: (percent = 0.0 || [gr state] == UIGestureRecognizerStateCancelled) [self cancelInteractiveTransition];else[self finishInteractiveTransition];self.interactive = NO;break;}}UIPercentDrivenInteractiveTransitionInteractive View Controller Transitions- (void)handlePinch:(UIPinchGestureRecognizer *)gr {CGFloat scale = [gr scale];switch ([gr state]) {case UIGestureRecognizerStateBegan:self.interactive = YES; _startScale = scale;[self.parent popViewControllerAnimated:YES];break;case UIGestureRecognizerStateChanged: {CGFloat percent = (1.0 - scale/_startScale);[self updateInteractiveTransition: (percent = 0.0 || [gr state] == UIGestureRecognizerStateCancelled) [self cancelInteractiveTransition];else[self finishInteractiveTransition];self.interactive = NO;break;}}UIPercentDrivenInteractiveTransitionInteractive View Controller Transitions- (void)handlePinch:(UIPinchGestureRecognizer *)gr {CGFloat scale = [gr scale];switch ([gr state]) {case UIGestureRecognizerStateBegan:self.interactive = YES; _startScale = scale;[self.parent popViewControllerAnimated:YES];break;case UIGestureRecognizerStateChanged: {CGFloat percent = (1.0 - scale/_startScale);[self updateInteractiveTransition: (percent = 0.0 || [gr state] == UIGestureRecognizerStateCancelled) [self cancelInteractiveTransition];else[self finishInteractiveTransition];self.interactive = NO;break;}}Interactive Collection View Layout TransitionsOlivier GutknechtUICollectionViewTransitionLayoutUICollectionViewTransitionLayout A new layout interpolating between two layoutsUICollectionViewTransitionLayout A new layout interpolating between two layouts Interactively or not, with the transitionProgress propertyUICollectionViewTransitionLayout A new layout interpolating between two layouts Interactively or not, with the transitionProgress property SubclassableUICollectionViewTransitionLayout A new layout interpolating between two layouts Interactively or not, with the transitionProgress property Subclassable Simple integration with view controller transitionsUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout BUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout B0.0Transition LayouttransitionProgressUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout B0.5Transition LayouttransitionProgressUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout B1.0Transition LayouttransitionProgressUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout B1.1Transition LayouttransitionProgressUICollectionViewTransitionLayoutCollection Views and Transition LayoutLayout A Layout B1.0Transition LayouttransitionProgressUICollectionViewInteractive TransitionsUICollectionViewInteractive Transitions New methods in UICollectionView- (UICollectionViewTransitionLayout *)startInteractiveTransitionToCollectionViewLayout:completion:- (void)finishInteractiveTransition- (void)cancelInteractiveTransition UICollectionViewInteractive Transitions New methods in UICollectionView- (UICollectionViewTransitionLayout *)startInteractiveTransitionToCollectionViewLayout:completion:- (void)finishInteractiveTransition- (void)cancelInteractiveTransition New delegate method- (UICollectionViewTransitionLayout *)collectionView:(UICollectionView*)vtransitionLayoutForOldLayout:(UICollectionViewLayout*)o newLayout:(UICollectionViewLayout*)nUICollectionViewInteractive Transitions New methods in UICollectionView- (UICollectionViewTransitionLayout *)startInteractiveTransitionToCollectionViewLayout:completion:- (void)finishInteractiveTransition- (void)cancelInteractiveTransition New delegate method- (UICollectionViewTransitionLayout *)collectionView:(UICollectionView*)vtransitionLayoutForOldLayout:(UICollectionViewLayout*)o newLayout:(UICollectionViewLayout*)n Does not replace- (void)setCollectionViewLayout:animated:Subclassing Transition LayoutSubclassing Transition Layout Implement your UICollectionViewTransitionLayout subclass!e.g. update cell positions based on gesture positionSubclassing Transition Layout Implement your UICollectionViewTransitionLayout subclass!e.g. update cell positions based on gesture position Create an instance of your own class in your delegate methodSubclassing Transition Layout Implement your UICollectionViewTransitionLayout subclass!e.g. update cell positions based on gesture position Create an instance of your own class in your delegate method On finish or cancel, UIKit animates at correct velocity!Track your own parameters updateValue:forAnimatedKey:!UIKit will monitor velocity!UIKit gives you in-sync values on completion and cancel with valueForAnimatedKey:DemoOther enhancementsCollection Views TransitionsOther enhancementsCollection Views Transitions Better control of target offsets everywhere targetContentOffsetForProposedContentOffset:Other enhancementsCollection Views Transitions Better control of target offsets everywhere targetContentOffsetForProposedContentOffset: Layouts are now notified on transitionsprepareForTransitionToLayout:prepareForTransitionFromLayout:finalizeLayoutTransitionOther enhancementsCollection Views Transitions Better control of target offsets everywhere targetContentOffsetForProposedContentOffset: Layouts are now notified on transitionsprepareForTransitionToLayout:prepareForTransitionFromLayout:finalizeLayoutTransition Better animations!Initial and final layout attributes are now supported!A new completion handlersetCollectionViewLayout:animated:completion:Cancellation and coordinatorsInteractive View Controller TransitionsUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingUIViewControllerTransitioningInteractive transitioning statesStart Interactive TransitionNo TransitionUpdate InteractiveTransitionTransition CompleteInteraction TransitionEndTransition CancelingNo TransitionTransitionFinishingUIViewControllerTransitioningCancellation and appearance callbacksTransition CompleteInteraction TransitionEndTransition CancelingTransitionFinishingInteractive transitioning states View controller appearance statesAppearing AppearedDisappeared DisappearingUIViewControllerTransitioningCancellation and appearance callbacksTransition CompleteInteraction TransitionEndTransition CancelingTransitionFinishingInteractive transitioning states View controller appearance statesAppearing AppearedDisappeared DisappearingUIViewControllerTransitioningCancellation and appearance callbacksTransition CompleteInteraction TransitionEndTransition CancelingTransitionFinishingInteractive transitioning states View controller appearance statesAppearing AppearedDisappeared DisappearingCanceling an interactive transitionInteractive View Controller TransitionsCanceling an interactive transitionInteractive View Controller Transitions Dont assume that viewDidAppear follows viewWillAppearCanceling an interactive transitionInteractive View Controller Transitions Dont assume that viewDidAppear follows viewWillAppear Make sure to undo any side effects!There is new API to help manage this@interface UIViewController(TransitionCoordinator)@property (nonatomic,retain) id transitionCoordinator;@end

Interactive View Controller Transitions@interface UIViewController(TransitionCoordinator)@property (nonatomic,retain) id transitionCoordinator;@end

Interactive View Controller Transitions

Interactive View Controller Transitions@protocol UIViewControllerTransitionCoordinator @optional- (BOOL) notifyWhenInteractionEndsUsingBlock:(void (^ (id