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
テストアーキテクチャ設計で実現する高品質で高スピードな開発の実践 / Test Architecture Design in Practice
ropqa
3
710
Larkご案内資料
customercloud
PRO
0
600
生成AIの利活用を加速させるための取り組み「prAIrie-dog」/ Shibuya_AI_1
visional_engineering_and_design
1
140
2.5Dモデルのすべて
yu4u
2
610
プロセス改善による品質向上事例
tomasagi
1
1.6k
エンジニアの育成を支える爆速フィードバック文化
sansantech
PRO
3
670
Datadogとともにオブザーバビリティを布教しよう
mego2221
0
130
マルチモーダル理解と生成の統合 DeepSeek Janus, etc... / Multimodal Understanding and Generation Integration
hiroga
0
360
オブザーバビリティの観点でみるAWS / AWS from observability perspective
ymotongpoo
7
1k
【Developers Summit 2025】プロダクトエンジニアから学ぶ、 ユーザーにより高い価値を届ける技術
niwatakeru
2
890
Ask! NIKKEI RAG検索技術の深層
hotchpotch
13
2.8k
SA Night #2 FinatextのSA思想/SA Night #2 Finatext session
satoshiimai
1
100
Featured
See All Featured
Become a Pro
speakerdeck
PRO
26
5.1k
Gamification - CAS2011
davidbonilla
80
5.1k
Speed Design
sergeychernyshev
25
780
The Language of Interfaces
destraynor
156
24k
Bash Introduction
62gerente
610
210k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
KATA
mclloyd
29
14k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
The Cult of Friendly URLs
andyhume
78
6.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Why Our Code Smells
bkeepers
PRO
335
57k
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