Custom UIViewController Transitions
-
Upload
jan-ilavsky -
Category
Software
-
view
1.589 -
download
0
description
Transcript of Custom UIViewController Transitions
![Page 1: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/1.jpg)
Custom UIViewController Transitions
Ján Ilavský - @split82
![Page 2: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/2.jpg)
iPhone OS 3.0
![Page 3: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/3.jpg)
![Page 4: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/4.jpg)
![Page 5: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/5.jpg)
iOS 7
![Page 6: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/6.jpg)
Modal View Controller
- (void)presentViewController:animated:completion: !
- (void)dismissViewControllerAnimated:completion:
![Page 7: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/7.jpg)
UIModalTransitionStyle modalTransitionStyle
![Page 8: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/8.jpg)
typedef NS_ENUM(NSInteger, UIModalTransitionStyle) { UIModalTransitionStyleCoverVertical = 0, UIModalTransitionStyleFlipHorizontal, UIModalTransitionStyleCrossDissolve, #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2 UIModalTransitionStylePartialCurl, #endif };
![Page 9: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/9.jpg)
UIModalPresentationStyle modalPresentationStyle
![Page 10: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/10.jpg)
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) { UIModalPresentationFullScreen = 0, #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2 UIModalPresentationPageSheet, UIModalPresentationFormSheet, UIModalPresentationCurrentContext, #endif #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0 UIModalPresentationCustom, UIModalPresentationNone = -1, #endif };
![Page 11: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/11.jpg)
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) { UIModalPresentationFullScreen = 0, #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2 UIModalPresentationPageSheet, UIModalPresentationFormSheet, UIModalPresentationCurrentContext, #endif #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0 UIModalPresentationCustom, UIModalPresentationNone = -1, #endif };
![Page 12: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/12.jpg)
Custom Fullscreen Non-interactive Transitions
![Page 13: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/13.jpg)
Demo
![Page 14: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/14.jpg)
TestViewController *viewController = [TestViewController new]; !viewController.transitioningDelegate = ??? ![self presentViewController:viewController animated:YES completion:nil];
![Page 15: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/15.jpg)
TestViewController *viewController = [TestViewController new]; !viewController.transitioningDelegate = ??? ![self presentViewController:viewController animated:YES completion:nil];
![Page 16: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/16.jpg)
@protocol UIViewControllerTransitioningDelegate <NSObject> !@optional !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source; !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator; !!@end
![Page 17: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/17.jpg)
@protocol UIViewControllerTransitioningDelegate <NSObject> !@optional !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source; !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator; !!@end
![Page 18: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/18.jpg)
@protocol UIViewControllerTransitioningDelegate <NSObject> !@optional !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source; !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator; !!@end
![Page 19: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/19.jpg)
UIViewController UIViewController
id <UIViewControllerTransitioningDelegate>
transitioningDelegate
animationControllerForPresentedController… animationControllerForDismissedController
id <UIViewControllerAnimatedTransitioning>
id <UIViewControllerAnimatedTransitioning>
present
dismiss
![Page 20: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/20.jpg)
@protocol UIViewControllerAnimatedTransitioning <NSObject> !!- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext; !- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext; !!@optional !- (void)animationEnded:(BOOL)transitionCompleted; !@end
![Page 21: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/21.jpg)
@protocol UIViewControllerAnimatedTransitioning <NSObject> !!- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext; !- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext; !!@optional !- (void)animationEnded:(BOOL)transitionCompleted; !@end
![Page 22: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/22.jpg)
UIView UIView
UIViewController UIViewController
![Page 23: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/23.jpg)
@protocol UIViewControllerAnimatedTransitioning <NSObject> !!- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext; !- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext; !!@optional !- (void)animationEnded:(BOOL)transitionCompleted; !@end
![Page 24: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/24.jpg)
@protocol UIViewControllerAnimatedTransitioning <NSObject> !!- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext; !- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext; !!@optional !- (void)animationEnded:(BOOL)transitionCompleted; !@end
![Page 25: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/25.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 26: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/26.jpg)
!Container View
UIView UIView
UIViewController UIViewController
![Page 27: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/27.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 28: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/28.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 29: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/29.jpg)
initialFrameForViewController finalFrameForViewController
from CGRectZero
to CGRectZero
![Page 30: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/30.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 31: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/31.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 32: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/32.jpg)
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; !UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; !!toViewController.view.alpha = 0.0f; toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; ![transitionContext.containerView addSubview:toViewController.view]; [UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { //[fromViewController.view removeFromSuperview]; [transitionContext completeTransition:YES]; }];
![Page 33: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/33.jpg)
Custom Non-Fullscreen Non-interactive Transitions
![Page 34: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/34.jpg)
TestViewController *viewController = [TestViewController new]; !viewController.modalPresentationStyle = UIModalPresentationCustom; viewController.transitioningDelegate = ??? ![self presentViewController:viewController animated:YES completion:nil];
![Page 35: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/35.jpg)
UIView
UIView
![Page 36: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/36.jpg)
Demo
![Page 37: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/37.jpg)
Presentation != Dismissal
![Page 38: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/38.jpg)
Presentation!
Container View
UIView UIView
UIViewController UIViewController
![Page 39: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/39.jpg)
Dismission!
Container View
UIView UIView
UIViewController UIViewController
![Page 40: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/40.jpg)
initialFrameForViewController finalFrameForViewController
from
to CGRectZero CGRectZero
Presentation
![Page 41: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/41.jpg)
initialFrameForViewController finalFrameForViewController
from CGRectZero
to CGRectZero
Dismissal
![Page 42: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/42.jpg)
viewWillDissapear !
viewDidDissapear
FromViewControllerPresentation
![Page 43: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/43.jpg)
viewWillAppear !
viewDidAppear
ToViewControllerDismissal
![Page 44: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/44.jpg)
[transitionContext.containerView addSubview:toViewController.view]; !toViewController.view.frame = CGRectInset([transitionContext initialFrameForViewController:fromViewController], 32.0f, 32.0f); !toViewController.view.alpha = 0.0f; ![UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }];
Presentation
![Page 45: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/45.jpg)
[UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ fromViewController.view.alpha = 0.0f; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }];
Dismissal
![Page 46: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/46.jpg)
Interactive Transitions
![Page 47: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/47.jpg)
start complete
![Page 48: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/48.jpg)
start complete
cancel
finish
updating
![Page 49: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/49.jpg)
Demo
![Page 50: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/50.jpg)
UIViewController UIViewController
id <UIViewControllerTransitioningDelegate>
transitioningDelegate
animationControllerForPresentedController… animationControllerForDismissedController
id <UIViewControllerAnimatedTransitioning>
id <UIViewControllerAnimatedTransitioning>
present
dismiss
![Page 51: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/51.jpg)
@protocol UIViewControllerTransitioningDelegate <NSObject> !@optional !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source; !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator; !!@end
![Page 52: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/52.jpg)
@protocol UIViewControllerTransitioningDelegate <NSObject> !@optional !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source; !!- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator; !!- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator; !!@end
![Page 53: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/53.jpg)
UIViewController UIViewController
id <UIViewControllerTransitioningDelegate>
transitioningDelegate
animationControllerForPresentedController… animationControllerForDismissedController
id <UIViewControllerAnimatedTransitioning>
id <UIViewControllerAnimatedTransitioning>
present
dismiss
![Page 54: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/54.jpg)
UIViewController UIViewController
id <UIViewControllerTransitioningDelegate>
transitioningDelegate
id <UIViewControllerAnimatedTransitioning>
id <UIViewControllerAnimatedTransitioning>
present
dismiss
id <UIViewControllerInteractiveTra
nsitioning>
id <UIViewControllerInteractiveTra
nsitioning>
![Page 55: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/55.jpg)
id <UIViewControllerInteractiveTransitioning>
![Page 56: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/56.jpg)
@protocol UIViewControllerInteractiveTransitioning <NSObject> !- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext; !@optional !- (CGFloat)completionSpeed; - (UIViewAnimationCurve)completionCurve; !@end
![Page 57: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/57.jpg)
UIPercentDrivenInteractiveTransition
![Page 58: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/58.jpg)
UIPercentDrivenInteractiveTransition
- (void)updateInteractiveTransition:(CGFloat)percentComplete; - (void)cancelInteractiveTransition; - (void)finishInteractiveTransition;
![Page 59: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/59.jpg)
CGFloat scale = [gestureRecognizer scale]; switch ([gestureRecognizer state]) { case UIGestureRecognizerStateBegan: transitionController.interactive = YES; _startScale = scale; [testViewController dismissViewControllerAnimated:YES completion:nil]; } break; case UIGestureRecognizerStateChanged: { CGFloat percent = (1.0 - scale/_startScale); [transitionController.percentDrivenInteractiveTransition updateInteractiveTransition: (percent <= 0.0) ? 0.0 : percent]; break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: if ([gestureRecognizer velocity] >= 0.0 || [gestureRecognizer state] == UIGestureRecognizerStateCancelled) { [transitionController.percentDrivenInteractiveTransition cancelInteractiveTransition]; } else { [transitionController.percentDrivenInteractiveTransition finishInteractiveTransition]; } break; default: break; }
![Page 60: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/60.jpg)
CGFloat scale = [gestureRecognizer scale]; switch ([gestureRecognizer state]) { case UIGestureRecognizerStateBegan: transitionController.interactive = YES; _startScale = scale; [testViewController dismissViewControllerAnimated:YES completion:nil]; } break; case UIGestureRecognizerStateChanged: { CGFloat percent = (1.0 - scale/_startScale); [transitionController.percentDrivenInteractiveTransition updateInteractiveTransition: (percent <= 0.0) ? 0.0 : percent]; break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: if ([gestureRecognizer velocity] >= 0.0 || [gestureRecognizer state] == UIGestureRecognizerStateCancelled) { [transitionController.percentDrivenInteractiveTransition cancelInteractiveTransition]; } else { [transitionController.percentDrivenInteractiveTransition finishInteractiveTransition]; } break; default: break; }
![Page 61: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/61.jpg)
Core Animation!!
+[UIView transitionFromView:toView:duration:options:completion:]!!
Custom Animations!!
UIView block-based animations
UIPercentDrivenInteractiveTransition
![Page 62: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/62.jpg)
[UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview];
[transitionContext completeTransition:YES]; }];
![Page 63: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/63.jpg)
[UIView animateWithDuration:self.duration delay:0.0 options:0 animations:^{ toViewController.view.alpha = 1.0f; } completion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; [transitionContext completeTransition: !transitionContext.transitionWasCancelled]; }];
![Page 64: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/64.jpg)
- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext { ! _transitionContext = transitionContext; _toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; _toViewController.view.alpha = 0.0f; _toViewController.view.frame = [transitionContext finalFrameForViewController:_toViewController]; [transitionContext.containerView addSubview:_toViewController.view]; }
id <UIViewControllerInteractiveTransitioning>
![Page 65: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/65.jpg)
id <UIViewControllerInteractiveTransitioning>
- (void)updateInteractiveTransition:(CGFloat)percentComplete { _toViewController.view.alpha = percentComplete; [_transitionContext updateInteractiveTransition:percentComplete]; }
![Page 66: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/66.jpg)
id <UIViewControllerInteractiveTransitioning>
- (void)cancelInteractiveTransition { [_transitionContext cancelInteractiveTransition]; [UIView animateWithDuration:0.3 delay:0.0 options:0 animations:^{ _toViewController.view.alpha = 0.0f; } completion:^(BOOL finished) { [_transitionContext completeTransition:!_transitionContext.transitionWasCancelled]; }]; }
![Page 67: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/67.jpg)
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear
![Page 68: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/68.jpg)
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear
![Page 69: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/69.jpg)
viewWillAppear viewWillDisappear
viewDidDisappear
![Page 70: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/70.jpg)
- (void)viewWillAppear:(BOOL)animated { [self doSomeSideEffectsAssumingViewDidAppearIsGoingToBeCalled]; id <UIViewControllerTransitionCoordinator> coordinator; coordinator = [self transitionCoordinator]; if(coordinator && [coordinator initiallyInteractive]) { [transitionCoordinator notifyWhenInteractionEndsUsingBlock: ^(id <UIViewControllerTransitionCoordinatorContext> ctx) { if(ctx.isCancelled) { [self undoSideEffects]; } }]; } }
UIViewControllerTransitionCoordinator
![Page 71: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/71.jpg)
UINavigationController
– pushViewController:animated: – popViewControllerAnimated: – popToRootViewControllerAnimated: – popToViewController:animated:
![Page 72: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/72.jpg)
- (id<UIViewControllerAnimatedTransitioning>)!navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC !toViewController:(UIViewController *)toVC
UINavigationControllerDelegate
- (id<UIViewControllerInteractiveTransitioning>)!navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
![Page 73: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/73.jpg)
UINavigationController
@property(nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer
![Page 74: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/74.jpg)
UITabBarController
@property(nonatomic, assign) UIViewController *selectedViewController @property(nonatomic) NSUInteger selectedIndex
![Page 75: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/75.jpg)
UITabBarControllerDelegate
- (id <UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>)animationController; !- (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC;
![Page 76: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/76.jpg)
finty fň
![Page 77: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/77.jpg)
![Page 78: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/78.jpg)
// Snapshot UIView *fromView = [fromViewController.view snapshotViewAfterScreenUpdates:NO]; !// Interactivity fromViewController.view.userInteractionEnabled = NO; toViewController.view.userInteractionEnabled = YES; transitionContext.containerView.userInteractionEnabled = YES; ![transitionContext.containerView addSubview:fromView]; [transitionContext.containerView addSubview:toViewController.view]; !// Finish before animation [transitionContext completeTransition:YES]; ![UIView animateWithDuration: . . .
![Page 79: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/79.jpg)
![Page 80: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/80.jpg)
// Prepare BitmapContext CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); GLubyte *textureData = malloc(textureWidth * textureHeight * 4); memset_pattern4(textureData, "\0\0\0\0", textureWidth * textureHeight * 4); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * textureWidth; NSUInteger bitsPerComponent = 8; CGContextRef bitmapContext = CGBitmapContextCreate(textureData, textureWidth, textureHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); // draw [view.layer renderInContext:bitmapContext]; CGContextRelease(bitmapContext); !// set data for texture glBindTexture(GL_TEXTURE_2D, texture); // set bitmap data into texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); // Don't need this data anymore free(textureData);
![Page 81: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/81.jpg)
fuck off view controllers
![Page 82: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/82.jpg)
![Page 83: Custom UIViewController Transitions](https://reader034.fdocuments.net/reader034/viewer/2022050808/54b6c2be4a795954358b45ae/html5/thumbnails/83.jpg)
Custom UIViewController Transitions
Ján Ilavský - @split82