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
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
120
SSMRunbook作成の勘所_20241120
koichiotomo
3
160
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
2
470
The Rise of LLMOps
asei
9
1.7k
アプリエンジニアのためのGraphQL入門.pdf
spycwolf
0
100
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
Terraform Stacks入門 #HashiTalks
msato
0
360
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
300
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
FlutterアプリにおけるSLI/SLOを用いたユーザー体験の可視化と計測基盤構築
ostk0069
0
110
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Why Our Code Smells
bkeepers
PRO
334
57k
Documentation Writing (for coders)
carmenintech
65
4.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
What's in a price? How to price your products and services
michaelherold
243
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
A Tale of Four Properties
chriscoyier
156
23k
Designing for Performance
lara
604
68k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
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