Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Custom Transitions in iOS 7 - Cocoaheads Berlin...
Search
Engin Kurutepe
October 16, 2013
Technology
1
790
Custom Transitions in iOS 7 - Cocoaheads Berlin Talk
Presented on 16.10.2013 in Cocoaheads Berlin
Engin Kurutepe
October 16, 2013
Tweet
Share
Other Decks in Technology
See All in Technology
AWS CDKの仕組み / how-aws-cdk-works
gotok365
10
730
SREのためのeBPF活用ステップアップガイド
egmc
1
780
Delta airlines®️ USA Contact Numbers: Complete 2025 Support Guide
airtravelguide
0
350
ゼロからはじめる採用広報
yutadayo
3
1k
2025-07-06 QGIS初級ハンズオン「はじめてのQGIS」
kou_kita
0
180
Rethinking Incident Response: Context-Aware AI in Practice
rrreeeyyy
1
230
Operating Operator
shhnjk
1
640
関数型プログラミングで 「脳がバグる」を乗り越える
manabeai
2
220
VS CodeとGitHub Copilotで爆速開発!アップデートの波に乗るおさらい会 / Rapid Development with VS Code and GitHub Copilot: Catch the Latest Wave
yamachu
2
300
CDKTFについてざっくり理解する!!~CloudFormationからCDKTFへ変換するツールも作ってみた~
masakiokuda
1
190
microCMSではじめるAIライティング
himaratsu
0
110
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
54
22k
Featured
See All Featured
Optimizing for Happiness
mojombo
379
70k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Designing Experiences People Love
moore
142
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
How to Ace a Technical Interview
jacobian
278
23k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Writing Fast Ruby
sferik
628
62k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
6
320
Transcript
Custom Transitions in iOS 7 by Engin Kurutepe Cocoaheads Berlin
- 16. Oct 2013
Who? • Engin Kurutepe – @ekurutepe • iOS Team Lead
at Txtr – www.txtr.com • Co-author of Developing an iOS 7 Edge http://bleedingedgepress.com/our-books/ developing-an-ios-7-edge/
Roadmap • Which transitions can be customized? • Anatomy of
a custom transition • A simple example • An interactive example
What can be customized? • Demo Time!
Anatomy A lot of protocols: • UIViewControllerTransitioningDelegate • UIViewControllerInteractiveTransitioning •
UIViewControllerAnimatedTransitioning • UIViewControllerTransitionCoordinator • UIViewControllerContextTransitioning • UIViewControllerTransitionCoordinatorContext
None
Tap!
Tap!
UIKit
UIKit -transitioningDelegate
UIKit TransitioningDelegate
UIKit TransitioningDelegate animationControllerForPresentedController: presentingController: sourceController:
UIKit TransitioningDelegate AnimationController
UIKit TransitioningDelegate AnimationController interactionControllerForPresentation:
UIKit TransitioningDelegate InteractionController AnimationController
UIKit TransitioningDelegate InteractionController AnimationController TransitioningContext
UIKit TransitioningDelegate InteractionController AnimationController TransitioningContext
in Practice… • Assign the transitioning delegate: • Full source
code on Github: https://github.com/iosedgeapp/iOSEdge - (IBAction) presentTapped:(UIButton*)sender { BEPSimpleImageViewController* ivc = [[BEPSimpleImageViewController alloc] init]; ivc.image = [UIImage imageNamed:@"Canyon.jpg"]; ivc.modalPresentationStyle = UIModalPresentationCustom; ivc.transitioningDelegate = self; [self presentViewController:ivc animated:YES completion:nil]; }
in Practice (cont’d) • Transitioning delegate vends an animator: -
(id<UIVCAnimatedTransitioning>) animationControllerForPresentedController:(UIVC*)modal presentingController:(UIVC*)parent sourceController:(UIVC*)source { return [[BEPModalTransitionAnimator alloc] initWithDirection:BEPModelTransitionDirectionPresent]; }
in Practice (cont’d) • Transitioning delegate does not vend an
interaction controller // Not implemented: //- (id<UIViewControllerInteractiveTransitioning>) interactionControllerForPresentation: (id<UIViewControllerAnimatedTransitioning>)animator
in Practice (cont’d) • The animator sets the duration for
the transition - (NSTimeInterval) transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext { return 0.75; }
in Practice (cont’d) • The animator performs the animations -
(void) animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { UIView* inView = [transitionContext containerView]; UIVC* fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIView* fromView = [fromVC view]; UIVC* toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIView* toView = [toVC view]; if (self.direction == BEPModelTransitionDirectionPresent) { [self performPresentationAnimations]; } else { [self performDismissalAnimations]; } }
in Practice (cont’d) • The animator inserts the presented view
• The animator MUST inform the context when transition is finished [inView insertSubview:toView aboveSubview:fromView]; [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 usingSpringWithDamping:DampingConstant initialSpringVelocity:InitialVelocity options:0 animations:^{ toView.alpha = 1.0; toView.frame = finalRect; toView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }];
How about interaction? • Demo Time!
How about interaction? • Transitioning Delegate must vend an interaction
controller • Apple provides the UIPercentDrivenInteractiveTransition class • Can drive UIView block-based animations
in Practice… • Transitioning Delegate vends an interaction controller: -
(id <UIVCInteractiveTransitioning>) navigationController:(UINavigationController*)nc interactionControllerForAnimationController:(id<UIVCAnimatedTransitioning>)animator { if (animator == _popper && _popper.interactive) { return _popper; } else { return nil; } }
in Practice (cont’d) • Previously during viewDidAppear… • but not
interactive, no? self.popper = [[BEPNavigationTransitionsPopAnimator alloc] initWithNavigationController:self]; _popper.interactive = NO;
in Practice (cont’d) • Previously during viewDidAppear… • but not
interactive, no? self.popper = [[BEPNavigationTransitionsPopAnimator alloc] initWithNavigationController:self]; _popper.interactive = NO; - (instancetype) initWithNavigationController:(UINavigationController*)nc { if (self = [super init]) { self.parent = nc; UIPinchGestureRecognizer* pgr = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)]; [self.parent.view addGestureRecognizer:pgr]; } return self; }
in Practice (cont’d) • but still not interactive?
in Practice (cont’d) • but still not interactive? - (void)
handlePinch:(UIPinchGestureRecognizer*)gr { CGFloat scale = [gr scale]; switch ([gr state]) { case UIGestureRecognizerStateBegan: self.interactive = YES; _startScale = scale; [self.parent popViewControllerAnimated:YES]; break;
in Practice (cont’d) • Popper driving the animation:
in Practice (cont’d) • Popper driving the animation: case UIGestureRecognizerStateChanged:
{ CGFloat percent = (1.0 - scale/_startScale); [self updateInteractiveTransition:MAX(percent,0.0)]; break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: if ([gr velocity] >= 0.0 || [gr state] == UIGestureRecognizerStateCancelled) { [self cancelInteractiveTransition]; } else { [self finishInteractiveTransition]; } self.interactive = NO; break; default: break; } }
Re-cap • Custom transitions very powerful • Complex set of
protocols • But in practice, it’s not that hard… • Source code for the examples available: https://github.com/iosedgeapp/iOSEdge
Further Reading • WWDC 2013 Session 218 • objc.io article
by Chris Eidhof http://www.objc.io/issue-5/view-controller- transitions.html • Developing an iOS 7 Edge (40% off for Cocoaheads): https://gumroad.com/ products/yLKx/cocoaheads