La traditionnelle mise à jour annuelle de nos petits bijoux de poche est moins discrète cette année avec une remise à plat de son design … Mais il y a aussi de très nombreuses nouveautés pour les développeurs. UIKit Dynamics, les motions events et les custom transitions en font partie. Elles renouvellent notre expérience des interfaces UIKit.
David Bonnet (créateur de CarMusic) est venu nous parler des custom transitions. Après une courte introduction et quelques exemples, vous devriez repartir avec plein d’idées pour personnaliser votre app…
14. UIKit Dynamics
- Arrivée de la physique dans
UIKit !
- Gravité / Ressorts / Gestion des
collisions...
- Interractions entre éléments
jeudi 24 octobre 13
25. Anatomie d’une transition
Début de la transition
Parent VC
Child A
View
Controllers
jeudi 24 octobre 13
Views
Containment
Controllers views
Superview
26. Anatomie d’une transition
Début de la transition
Window
Parent
View
Parent VC
Child A
View
Controllers
jeudi 24 octobre 13
Views
Containment
View
Controllers views
Superview
27. Anatomie d’une transition
Début de la transition
Window
Parent
View
Parent VC
Child A
Child A
View
View
Controllers
jeudi 24 octobre 13
Views
Containment
Controllers views
View
View
Superview
29. Anatomie d’une transition
Fin de la transition
Window
Parent
View
Parent VC
Child A
View
Controllers
jeudi 24 octobre 13
Views
Containment
View
Controllers views
Superview
30. Anatomie d’une transition
Fin de la transition
Window
Parent
View
Parent VC
Child A
View
Child B
View
Controllers
jeudi 24 octobre 13
Views
Containment
Controllers views
Superview
31. Anatomie d’une transition
Fin de la transition
Window
Parent
View
Parent VC
Child A
Child B
View
Controllers
jeudi 24 octobre 13
Views
Containment
Child B
View
Controllers views
View
View
Superview
32. Anatomie d’une transition
Fin de la transition
Window
Parent
View
Parent VC
Child A
View
View
Controllers
jeudi 24 octobre 13
View
Views
Child A
Child B
Containment
Child B
View
Controllers views
View
View
Superview
34. Anatomie d’une transition
Window
Etat intérmédiaire
Parent
Child A
Child B
View
View
Child A
Container view
View
jeudi 24 octobre 13
View
Child B
View
35. Anatomie d’une transition
Window
Etat intérmédiaire
Parent
Child A
Child B
Child B
View
View
Container view
Child A
View
jeudi 24 octobre 13
View
View
36. Anatomie d’une transition
Window
Etat intérmédiaire
Parent
Child A
Child B
Container view
View
View
Child B
Child A
View
View
jeudi 24 octobre 13
View
38. Anatomie d’une transition
- Ce qu’il faut retenir :
- iOS crée la container view
- Calcule la position de départ et de fin
- Notifie les view controllers des mouvements
(Mise à jour des structures, Callbacks, ...)
jeudi 24 octobre 13
39. Anatomie d’une transition
- Ce qu’il faut retenir :
- iOS crée la container view
- Calcule la position de départ et de fin
- Notifie les view controllers des mouvements
(Mise à jour des structures, Callbacks, ...)
L’éventuelle animation et/ou interraction
doit être définie
jeudi 24 octobre 13
42. Custom transitions : les protocols
- Les contrôleurs d’animations et d’interactions doivent
être fournis par les delegates respectifs
<UIViewControllerTransitioningDelegate>
<UINavigationControllerDelegate>
<UITabBarControllerDelegate>
jeudi 24 octobre 13
43. Custom transitions : les protocols
- Les contrôleurs d’animations et d’interactions doivent
être fournis par les delegates respectifs
<UIViewControllerTransitioningDelegate>
<UINavigationControllerDelegate>
<UITabBarControllerDelegate>
- Les contrôleurs d’animations répondent au protocol
<UIViewControllerAnimatedTransitioning>
jeudi 24 octobre 13
44. Custom transitions : les protocols
- Les contrôleurs d’animations et d’interactions doivent
être fournis par les delegates respectifs
<UIViewControllerTransitioningDelegate>
<UINavigationControllerDelegate>
<UITabBarControllerDelegate>
- Les contrôleurs d’animations répondent au protocol
<UIViewControllerAnimatedTransitioning>
- Les contrôleurs d’interactions répondent au protocol
<UIViewControllerInteractiveTransitioning>
jeudi 24 octobre 13
45. Custom transitions : les protocols
- Les contrôleurs d’animations et d’interactions doivent
être fournis par les delegates respectifs
<UIViewControllerTransitioningDelegate>
<UINavigationControllerDelegate>
<UITabBarControllerDelegate>
- Les contrôleurs d’animations répondent au protocol
<UIViewControllerAnimatedTransitioning>
- Les contrôleurs d’interactions répondent au protocol
<UIViewControllerInteractiveTransitioning>
- iOS fourni aux contrôleurs un contexte de transition
<UIViewControllerContextTransitioning>
jeudi 24 octobre 13
47. <UIViewControllerContextTransitioning>
//Le contexte de transition fourni par iOS
@protocol UIViewControllerContextTransitioning <NSObject>
// The view in which the animated transition should take place.
- (UIView *)containerView;
// Two keys for the method below are currently defined by the system
// UITransitionContextToViewControllerKey
// 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
jeudi 24 octobre 13
48. <UIViewControllerContextTransitioning>
//Le contexte de transition fourni par iOS
@protocol UIViewControllerContextTransitioning <NSObject>
// The view in which the animated transition should take place.
- (UIView *)containerView;
// Two keys for the method below are currently defined by the system
// UITransitionContextToViewControllerKey
// 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
jeudi 24 octobre 13
49. <UIViewControllerContextTransitioning>
//Le contexte de transition fourni par iOS
@protocol UIViewControllerContextTransitioning <NSObject>
// The view in which the animated transition should take place.
- (UIView *)containerView;
// Two keys for the method below are currently defined by the system
// UITransitionContextToViewControllerKey
// 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
jeudi 24 octobre 13
50. <UIViewControllerContextTransitioning>
//Le contexte de transition fourni par iOS
@protocol UIViewControllerContextTransitioning <NSObject>
// The view in which the animated transition should take place.
- (UIView *)containerView;
// Two keys for the method below are currently defined by the system
// UITransitionContextToViewControllerKey
// 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
jeudi 24 octobre 13
51. <UIViewControllerContextTransitioning>
//Le contexte de transition fourni par iOS
@protocol UIViewControllerContextTransitioning <NSObject>
// The view in which the animated transition should take place.
- (UIView *)containerView;
// Two keys for the method below are currently defined by the system
// UITransitionContextToViewControllerKey
// 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
jeudi 24 octobre 13
53. <UIViewControllerAnimatedTransitioning>
//Le contrôleur d’animation
@protocol UIViewControllerAnimatedTransitioning <NSObject>
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)ctx;
// This method can only be a nop if the transition is interactive and not a
// percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)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
jeudi 24 octobre 13
54. <UIViewControllerAnimatedTransitioning>
//Le contrôleur d’animation
@protocol UIViewControllerAnimatedTransitioning <NSObject>
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)ctx;
// This method can only be a nop if the transition is interactive and not a
// percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)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
jeudi 24 octobre 13
55. <UIViewControllerAnimatedTransitioning>
//Le contrôleur d’animation
@protocol UIViewControllerAnimatedTransitioning <NSObject>
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)ctx;
// This method can only be a nop if the transition is interactive and not a
// percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)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
jeudi 24 octobre 13
56. <UIViewControllerAnimatedTransitioning>
//Le contrôleur d’animation
@protocol UIViewControllerAnimatedTransitioning <NSObject>
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)ctx;
// This method can only be a nop if the transition is interactive and not a
// percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)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
jeudi 24 octobre 13
73. UINavigationController
Interactive pop gesture sur toutes les apps
iOS 7
Custom interactive transitions
Pas forcément pilotées par un geste
Gestion de l’annulation
Interactive Transitions
jeudi 24 octobre 13
74. UINavigationController
Interactive pop gesture sur toutes les apps
iOS 7
Custom interactive transitions
Pas forcément pilotées par un geste
Gestion de l’annulation
UIPercentDrivenInteractiveTransition
Interactive Transitions
jeudi 24 octobre 13
76. États d’une transition interactive
États
Aucune
transition
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
77. États d’une transition interactive
États
Aucune
transition
Début de la
transition
interactive
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
78. États d’une transition interactive
États
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
79. États d’une transition interactive
États
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Fin de la
transition
interactive
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
80. États d’une transition interactive
États
Transition
annulée
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Fin de la
transition
interactive
Transition
terminée
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
81. États d’une transition interactive
États
Transition
annulée
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Fin de la
transition
interactive
Transition
terminée
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
82. États d’une transition interactive
États
Transition
annulée
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Fin de la
transition
interactive
Transition
achevée
Transition
terminée
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
83. États d’une transition interactive
États
Transition
annulée
Aucune
transition
Début de la
transition
interactive
Mise à jour
transition
interactive
Fin de la
transition
interactive
Transition
achevée
Transition
terminée
Acteurs
Interactive Event
Handler
jeudi 24 octobre 13
Interactor
Animator
Context
90. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
91. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
92. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
93. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
94. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
95. <UIPercentDrivenInteractiveTransition>
//La manière la plus simple
// The associated animation controller must animate its transition using UIView animation APIs.
@interface UIPercentDrivenInteractiveTransition : NSObject
<UIViewControllerInteractiveTransitioning>
@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;
@end
jeudi 24 octobre 13
99. UICollectionView interactive transitions
- Le suivi de la progression via
-
transitionProgress
de 0.f à 1.1f (pour l’effet de bouncing)
- Nouvelles méthodes sur UICollectionView
- (UICollectionViewTransitionLayout *)
startInteractiveTransitionToCollectionViewLayout:completion:
- (void)finishInteractiveTransition
- (void)cancelInteractiveTransition
jeudi 24 octobre 13
100. UICollectionView interactive transitions
- Le suivi de la progression via
-
transitionProgress
de 0.f à 1.1f (pour l’effet de bouncing)
- Nouvelles méthodes sur UICollectionView
- (UICollectionViewTransitionLayout *)
startInteractiveTransitionToCollectionViewLayout:completion:
- (void)finishInteractiveTransition
- (void)cancelInteractiveTransition
- Enrichissement du delegate
- (UICollectionViewTransitionLayout *)collectionView:(UICollectionView*)v
transitionLayoutForOldLayout:(UICollectionViewLayout*)o
newLayout:(UICollectionViewLayout*)n
jeudi 24 octobre 13
103. Appearance callbacks (with cancel)
États de transition d’une interaction
Transition
annulée
Fin de la
transition
interactive
Transition
achevée
Transition
terminée
jeudi 24 octobre 13
104. Appearance callbacks (with cancel)
États de transition d’une interaction
États d’apparance d’un contrôleur
Appearing
Appeared
Disappeared
Disappearing
Transition
annulée
Fin de la
transition
interactive
Transition
achevée
Transition
terminée
jeudi 24 octobre 13
105. Appearance callbacks (with cancel)
États de transition d’une interaction
États d’apparance d’un contrôleur
Appearing
Appeared
Disappeared
Disappearing
Transition
annulée
Fin de la
transition
interactive
Transition
achevée
Transition
terminée
viewDidAppear:
jeudi 24 octobre 13
n’est pas toujours appelé après viewWillAppear: