Core animation pour les nul ls et les moins nuls

Mathieu Vaidis
Mathieu VaidisDigital Marketing Consultant
CoreAnimation pour les
NULLs et les moins nuls



           Romain Vincens
        romain@nomadplanet.fr
CoreAnimation
        c’est quoi?
• QuartzCore.framework
• Visualisation de données
• Accélération GPU
• Threads séparés
• Développements simplifiés
          CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Pour le développeur

• État de départ / état d’arrivée
• Interpolation automatique:
  «Générateur d’états intermédiaires»
  courbes-fonction du temps
• Niveau UIView / Niveau CALayer
          CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Courbes
 Linéaire




 EaseIn




EaseOut




EaseInOut

            CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animations
                    niveau UIKit
   •   OS 2.0 et +

[UIView   beginAnimations:nil context:nil];
[UIView   setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView   setAnimationDuration:0.5];
[UIView   setAnimationDelegate:myView];
[UIView   setAnimationDidStopSelector:@selector(removeFromSuperview)];

[myView setAlpha:0.0];

[UIView commitAnimations];




                      CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animations
                 niveau UIKit
  •   OS 4.0 et +

[UIView animateWithDuration:0.5
                       delay:0.0
                     options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                      [myView setAlpha:0.0];
                 }
                 completion:^(BOOL finished) {
                      [myView removeFromSuperview];
                 }];




                   CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Enchainements
• Syntaxe «classique»
- (void) anim1 {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    if(someConditions) {
        [UIView setAnimationDidStopSelector:@selector(anim2)];
    } else {
        [UIView setAnimationDidStopSelector:@selector(anim3)];
    }
    // Animations
    [UIView commitAnimations];
}

                 CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Enchainements
    • Syntaxe des blocs
- (void) anim1 {
    [UIView animateWithDuration:0.5
                           delay:0.0
                         options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         // animate stuff
                     }
                     completion:^(BOOL finished) {
                         [UIView animateWithDuration:0.5
                                          animations:^{
                                             // animate something else
                                          }];
                     }];
}


                     CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
• Passage de blocs en paramètres
- (void) someMethod {
    ...
    [self animateWithCompletionBlock:^{
               [object1 removeFromSuperview];
            }];
    ...
}

- (void) animateWithCompletionBlock:(void (^)(void))block {
    [UIView animateWithDuration:0.5
                           delay:0.0
                         options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         // animate
                     }
                     completion:^(BOOL finished) {
                         if(block != nil) {
                            block();
                         }
                     }];
}
                    CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animations
       niveau CALayer
• Toute UIView a une layer non nulle
• Cette layer est un CALayer
• UIView est une couche d’abstraction au-
  dessus de CALayer

  ex: myView.alpha = 0.0; <~> myView.layer.opacity = 0.0;

• Sublayers
              CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Core Animation
Vue d’ensemble




  CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Les animations
• CAPropertyAnimation
 •   keypath : la propriété à animer

• CABasicAnimation
 •   fromValue, toValue, byValue

• CAKeyframeAnimation
 •   values/path

 •   keytimes, timingFunctions, calculationModes

• CAAnimationGroup
               CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animatable properties
                                                                                       shadowOpacity
                                    shadowOffset
      contentsRect
                                                                       compositingFilter
sublayers                   transform
        doubleSided
                                                                         borderWidth
                anchorPoint
opacity
                                                             contents                    zPosition
              backgroundColor                    cornerRadius
shadowColor                                                                       masksToBounds
                                                      filters
     frame             position                                                       borderColor
                                                hidden
               backgroundFilters                              bounds
sublayerTransform                           mask                                     shadowRadius
                     CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Les animations
 CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
 anim.duration = 0.5;
 anim.fromValue = [NSNumber numberWithFloat:1.0];
 anim.toValue = [NSNumber numberWithFloat:0.1];
 [myLayer addAnimation:theAnimation forKey:@"animateOpacity"];
 [myLayer setOpacity:[NSNumber numberWithFLoat:0.1]];



• Que fais CoreAnimation?
  • Création de toutes les frames, par interpolation
  • addAnimation joue l’animation, frame par frame
      ce sont les presentationLayer
  • En fin d’animation, la layer prendra la valeur
      spécifiée après l’ajout de l’animation
                       CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Les animations
   CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
   anim.duration = 0.5;
   anim.fromValue = [NSNumber numberWithFloat:1.0];
   anim.toValue = [NSNumber numberWithFloat:0.1];
   [myLayer addAnimation:theAnimation forKey:@"animateOpacity"];
   [myLayer setOpacity:[NSNumber numberWithFLoat:0.1]];



                Exemple sur une animation linéaire
 État                                                                                 État
                                        presentationLayers
initial                                                                               final




                                                  0.5s
                         CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Transactions
• Implicites vs explicites
• Les transactions explicites permettent
 • d’overrider les propriétés des animations
 • de spécifier un bloc de completion
   [CATransaction begin];
   [CATransaction setAnimationDuration:0.3];
   [CATransaction setCompletionBlock:^{
       [self doSomething];
   }];
   // Add animation to layer
   [CATransaction commit];



                    CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animer des
      propriétés custom
• CoreAnimation peut animer des propriétés qui
  ne font pas partie des animatable properties
• Du moment qu’elles représentent des nombres
  (types primitifs ou NSNumbers)
• A charge au développeur de dire à quoi
  correspondent ces propriétés

              CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Animer des
      propriétés custom
• Hériter de CALayer
• 3 méthodes indispensables à implémenter
  - (id)initWithLayer:(id)layer;
  + (BOOL)needsDisplayForKey:(NSString*)key;
  - (void)drawInContext:(CGContextRef)ctx;




              CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Démo


c’est mieux qu’un long discours




     CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Performances

• Très bonnes (GPU)
• Du moment que les layers restent opaques
     layer.opaque = YES;



• Mais dans certains cas on ne peut faire autrement
              CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Démo


         (ça sent la fin)




CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
One more thing


parce que moi aussi je le vaux bien !




      CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
Des questions?

                   Merci



  CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
1 sur 23

Recommandé

CA Layer / Core Animation {Cocoaheads Montpellier} par
CA Layer / Core Animation {Cocoaheads Montpellier}CA Layer / Core Animation {Cocoaheads Montpellier}
CA Layer / Core Animation {Cocoaheads Montpellier}Idean France
676 vues20 diapositives
Kiedy sprzedawać akcje? par
Kiedy sprzedawać akcje?Kiedy sprzedawać akcje?
Kiedy sprzedawać akcje?Tobiasz Maliński
1K vues26 diapositives
Pt. homebrace indonesia company and product profile par
Pt. homebrace indonesia company and product profilePt. homebrace indonesia company and product profile
Pt. homebrace indonesia company and product profilebernard ade permatista
995 vues64 diapositives
Muli navi gps_ru par
Muli navi gps_ruMuli navi gps_ru
Muli navi gps_rua1333
557 vues24 diapositives
Spec ops service corporate overview par
Spec ops service corporate overviewSpec ops service corporate overview
Spec ops service corporate overviewChip Bayless
1.1K vues15 diapositives
Zorgvuldig met social media. Zorgnet Vlaanderen par
Zorgvuldig met social media. Zorgnet VlaanderenZorgvuldig met social media. Zorgnet Vlaanderen
Zorgvuldig met social media. Zorgnet VlaanderenPixular - Kortrijk - Roeselare - Stefaan Lammertyn
1.5K vues204 diapositives

Contenu connexe

Similaire à Core animation pour les nul ls et les moins nuls

Introduction à MacRuby - OSDC.fr 2009 par
Introduction à MacRuby - OSDC.fr 2009Introduction à MacRuby - OSDC.fr 2009
Introduction à MacRuby - OSDC.fr 2009guest60b8020b
500 vues47 diapositives
Introduction à MacRuby par
Introduction à MacRubyIntroduction à MacRuby
Introduction à MacRubyOlivier Gutknecht
918 vues44 diapositives
Animations avec Jetpack Compose par
Animations avec Jetpack ComposeAnimations avec Jetpack Compose
Animations avec Jetpack ComposeAntoine Robiez
45 vues27 diapositives
Javascript proprement par
Javascript proprementJavascript proprement
Javascript proprementGuillaume Collic
1K vues64 diapositives
Android rendu et performance - 17 avril 2012 par
Android rendu et performance - 17 avril 2012Android rendu et performance - 17 avril 2012
Android rendu et performance - 17 avril 2012Paris Android User Group
912 vues82 diapositives
Présentation de RMI Java par
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI JavaZakaria Bouazza
3.1K vues19 diapositives

Similaire à Core animation pour les nul ls et les moins nuls(15)

Introduction à MacRuby - OSDC.fr 2009 par guest60b8020b
Introduction à MacRuby - OSDC.fr 2009Introduction à MacRuby - OSDC.fr 2009
Introduction à MacRuby - OSDC.fr 2009
guest60b8020b500 vues
Tour D Horizon Des Drawables par Cyril Mottier
Tour D Horizon Des DrawablesTour D Horizon Des Drawables
Tour D Horizon Des Drawables
Cyril Mottier4.2K vues
BlaBlaCar - Going Native ! par Erwann Robin
BlaBlaCar - Going Native ! BlaBlaCar - Going Native !
BlaBlaCar - Going Native !
Erwann Robin1.7K vues
Cappuccino - ou comment créer une application web en 5 minutes par Geeks Anonymes
Cappuccino - ou comment créer une application web en 5 minutes Cappuccino - ou comment créer une application web en 5 minutes
Cappuccino - ou comment créer une application web en 5 minutes
Geeks Anonymes690 vues
ToulouseJUG - REX Flex, Spring & Agilité par Nicolas Deverge
ToulouseJUG - REX Flex, Spring & AgilitéToulouseJUG - REX Flex, Spring & Agilité
ToulouseJUG - REX Flex, Spring & Agilité
Nicolas Deverge3.7K vues
.Net pour le développeur Java - une source d'inspiration? par Rui Carvalho
.Net pour le développeur Java - une source d'inspiration?.Net pour le développeur Java - une source d'inspiration?
.Net pour le développeur Java - une source d'inspiration?
Rui Carvalho931 vues

Plus de Mathieu Vaidis

Responsive design bookmarklet par
Responsive design bookmarkletResponsive design bookmarklet
Responsive design bookmarkletMathieu Vaidis
317 vues15 diapositives
Place it par
Place itPlace it
Place itMathieu Vaidis
259 vues19 diapositives
Icon preview tool par
Icon preview toolIcon preview tool
Icon preview toolMathieu Vaidis
339 vues9 diapositives
Smart app banners par
Smart app bannersSmart app banners
Smart app bannersMathieu Vaidis
589 vues7 diapositives
Promotee par
PromoteePromotee
PromoteeMathieu Vaidis
248 vues5 diapositives
Exec summary of the Apple AppStore marketing and advertising guidelines for d... par
Exec summary of the Apple AppStore marketing and advertising guidelines for d...Exec summary of the Apple AppStore marketing and advertising guidelines for d...
Exec summary of the Apple AppStore marketing and advertising guidelines for d...Mathieu Vaidis
448 vues41 diapositives

Plus de Mathieu Vaidis(8)

Core animation pour les nul ls et les moins nuls

  • 1. CoreAnimation pour les NULLs et les moins nuls Romain Vincens romain@nomadplanet.fr
  • 2. CoreAnimation c’est quoi? • QuartzCore.framework • Visualisation de données • Accélération GPU • Threads séparés • Développements simplifiés CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 3. Pour le développeur • État de départ / état d’arrivée • Interpolation automatique: «Générateur d’états intermédiaires» courbes-fonction du temps • Niveau UIView / Niveau CALayer CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 4. Courbes Linéaire EaseIn EaseOut EaseInOut CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 5. Animations niveau UIKit • OS 2.0 et + [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:myView]; [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)]; [myView setAlpha:0.0]; [UIView commitAnimations]; CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 6. Animations niveau UIKit • OS 4.0 et + [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [myView setAlpha:0.0]; } completion:^(BOOL finished) { [myView removeFromSuperview]; }]; CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 7. Enchainements • Syntaxe «classique» - (void) anim1 { [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; if(someConditions) { [UIView setAnimationDidStopSelector:@selector(anim2)]; } else { [UIView setAnimationDidStopSelector:@selector(anim3)]; } // Animations [UIView commitAnimations]; } CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 8. Enchainements • Syntaxe des blocs - (void) anim1 { [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ // animate stuff } completion:^(BOOL finished) { [UIView animateWithDuration:0.5 animations:^{ // animate something else }]; }]; } CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 9. • Passage de blocs en paramètres - (void) someMethod { ... [self animateWithCompletionBlock:^{ [object1 removeFromSuperview]; }]; ... } - (void) animateWithCompletionBlock:(void (^)(void))block { [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ // animate } completion:^(BOOL finished) { if(block != nil) { block(); } }]; } CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 10. Animations niveau CALayer • Toute UIView a une layer non nulle • Cette layer est un CALayer • UIView est une couche d’abstraction au- dessus de CALayer ex: myView.alpha = 0.0; <~> myView.layer.opacity = 0.0; • Sublayers CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 11. Core Animation Vue d’ensemble CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 12. Les animations • CAPropertyAnimation • keypath : la propriété à animer • CABasicAnimation • fromValue, toValue, byValue • CAKeyframeAnimation • values/path • keytimes, timingFunctions, calculationModes • CAAnimationGroup CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 13. Animatable properties shadowOpacity shadowOffset contentsRect compositingFilter sublayers transform doubleSided borderWidth anchorPoint opacity contents zPosition backgroundColor cornerRadius shadowColor masksToBounds filters frame position borderColor hidden backgroundFilters bounds sublayerTransform mask shadowRadius CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 14. Les animations CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"]; anim.duration = 0.5; anim.fromValue = [NSNumber numberWithFloat:1.0]; anim.toValue = [NSNumber numberWithFloat:0.1]; [myLayer addAnimation:theAnimation forKey:@"animateOpacity"]; [myLayer setOpacity:[NSNumber numberWithFLoat:0.1]]; • Que fais CoreAnimation? • Création de toutes les frames, par interpolation • addAnimation joue l’animation, frame par frame ce sont les presentationLayer • En fin d’animation, la layer prendra la valeur spécifiée après l’ajout de l’animation CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 15. Les animations CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"]; anim.duration = 0.5; anim.fromValue = [NSNumber numberWithFloat:1.0]; anim.toValue = [NSNumber numberWithFloat:0.1]; [myLayer addAnimation:theAnimation forKey:@"animateOpacity"]; [myLayer setOpacity:[NSNumber numberWithFLoat:0.1]]; Exemple sur une animation linéaire État État presentationLayers initial final 0.5s CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 16. Transactions • Implicites vs explicites • Les transactions explicites permettent • d’overrider les propriétés des animations • de spécifier un bloc de completion [CATransaction begin]; [CATransaction setAnimationDuration:0.3]; [CATransaction setCompletionBlock:^{ [self doSomething]; }]; // Add animation to layer [CATransaction commit]; CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 17. Animer des propriétés custom • CoreAnimation peut animer des propriétés qui ne font pas partie des animatable properties • Du moment qu’elles représentent des nombres (types primitifs ou NSNumbers) • A charge au développeur de dire à quoi correspondent ces propriétés CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 18. Animer des propriétés custom • Hériter de CALayer • 3 méthodes indispensables à implémenter - (id)initWithLayer:(id)layer; + (BOOL)needsDisplayForKey:(NSString*)key; - (void)drawInContext:(CGContextRef)ctx; CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 19. Démo c’est mieux qu’un long discours CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 20. Performances • Très bonnes (GPU) • Du moment que les layers restent opaques layer.opaque = YES; • Mais dans certains cas on ne peut faire autrement CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 21. Démo (ça sent la fin) CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 22. One more thing parce que moi aussi je le vaux bien ! CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011
  • 23. Des questions? Merci CoreAnimation - Romain Vincens - Cocoaheads - 10 mars 2011