SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
ANIMATIONS IN IOS
Created by Anna Dovnar
THERE ARE TWO WAYS TO WORK WITH
ANIMATION. THE FIRST WAY IS VIA UIKIT,
WHICH INCLUDES VIEW-BASED ANIMATIONS
AS WELL AS ANIMATED TRANSITIONS
BETWEEN CONTROLLERS. THE SECOND WAY
IS WORKING WITH CORE ANIMATION
LAYERS DIRECTLY FOR FINER-GRAINED
CONTROL.
UIKIT ANIMATION
• Transitions between controllers
• Transitions between views
• View property animation
VIEW CONTROLLER
TRANSITIONS
• CrossDissolve
• CoverVertical
• FlipHorizontal
• PartialCurl
UIVIEWCONTROLLER PROVIDES BUILT-IN
SUPPORT FOR TRANSITIONING BETWEEN
VIEW CONTROLLERS THROUGH THE
PRESENTVIEWCONTROLLER METHOD.
VIEW TRANSITIONS
IN ADDITION TO TRANSITIONS BETWEEN
CONTROLLERS, UIKIT ALSO SUPPORTS
ANIMATING TRANSITIONS BETWEEN VIEWS
TO SWAP ONE VIEW FOR ANOTHER.
VIEW PROPERTY ANIMATIONS
• Frame
• Bounds
• Center
• Alpha
• Transform
• Color
STARTING ANIMATIONS USING
THE BEGIN/COMMIT METHODS
STARTING ANIMATIONS USING
THE BLOCK-BASED METHODS
• animateWithDuration:animations:
• animateWithDuration:animations:completion:
• animateWithDuration:delay:options:animations:co
mpletion:
CONFIGURING THE PARAMETERS
FOR BEGIN/COMMIT ANIMATIONS
• setAnimationStartDate:
• setAnimationDelay:
• setAnimationDuration:
• setAnimationCurve:
• setAnimationRepeatCount:
• setAnimationRepeatAutoreverses:
• setAnimationDelegate:
• setAnimationWillStartSelector:
• setAnimationDidStopSelector:
• setAnimationBeginsFromCurrentState:
ANIMATION DELEGATE
The animationID and context parameters for both methods are the same
parameters that you passed to the beginAnimations:context: method at the
beginning of the animation block:
• animationID—An application-supplied string used to identify the
animation.
• context—An application-supplied object that you can use to pass
additional information to the delegate.
The setAnimationDidStopSelector: selector method has an additional parameter—
a Boolean value that is YES if the animation ran to completion. If the value of this
parameter is NO, the animation was either canceled or stopped prematurely by
another animation.
CORE ANIMATION
UIVIEW ANIMATIONS ALLOW A LOT OF CAPABILITY
AND SHOULD BE USED IF POSSIBLE DUE TO THE EASE
OF IMPLEMENTATION. HOWEVER, SOME THINGS
CANNOT BE DONE WITH UIVIEW ANIMATIONS, SUCH
AS ANIMATING ADDITIONAL PROPERTIES THAT
CANNOT BE ANIMATED WITH A VIEW, OR
INTERPOLATING ALONG A NON-LINEAR PATH. IN SUCH
CASES WHERE YOU NEED FINER CONTROL, CORE
ANIMATION CAN BE USED DIRECTLY AS WELL.
ANIMATION HAPPENS VIA
LAYERS
Layer animations can be either implicit or explicit
IMPLICIT ANIMATIONS
TO ADD AN IMPLICIT ANIMATION FOR THE
LAYER, SIMPLY WRAP PROPERTY CHANGES
IN A CATRANSACTION. THIS ALLOWS
ANIMATING PROPERTIES THAT WOULD NOT
BE ANIMATABLE WITH A VIEW ANIMATION
EXPLICIT ANIMATIONS
LET YOU ENCAPSULATE ANIMATIONS THAT
ARE THEN EXPLICITLY ADDED TO A LAYER.
THESE ALLOW FINER-GRAINED CONTROL
OVER ANIMATIONS
STOPPING AN EXPLICIT
ANIMATION WHILE IT IS RUNNING
• To remove a single animation object from the layer, call
the layer’s removeAnimationForKey: method to remove
your animation object. This method uses the key that was
passed to the addAnimation:forKey: method to identify
the animation. The key you specify must not be nil.
• To remove all animation objects from the layer, call the
layer’s removeAllAnimations method. This method
removes all ongoing animations immediately and
redraws the layer using its current state information.
ANIMATIONS WITH AUTO
LAYOUT
• Create outlet for constraint
• Change constraint.constant value
• Don’t forget to call layoutIfNeeded
ANIMATIONS IN APPLE WATCH
ANIMATION IS NOT REALLY SUPPORTED
TO MAKE SOMETHING APPEAR ANIMATED,
YOU HAVE TO PRE-GENERATE A TON OF
IMAGES, AND THEN CYCLE THROUGH LIKE A
FLIP-BOOK. THE ERA OF THE ANIMATED GIF
IS BACK!
[self.imgSpriteAnimation setImageNamed:@"dragon-"];
[self.imgSpriteAnimation startAnimatingWithImagesInRange:NSMakeRange(0, 60)
duration:1.0 repeatCount:0];
FOR AN EXAMPLE OF THIS, CHECK OUT
APPLE’S LISTER EXAMPLE. IN THE WATCH
APP’S GLANCE, YOU’LL SEE THERE ARE 360
IMAGES REPRESENTING A CIRCLE
ANIMATION!
A short guide to animations in iOS

Weitere ähnliche Inhalte

Ähnlich wie A short guide to animations in iOS

Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core AnimationJohn Wilker
 
Animations - Part 2 - Transcript.pdf
Animations - Part 2 - Transcript.pdfAnimations - Part 2 - Transcript.pdf
Animations - Part 2 - Transcript.pdfShaiAlmog1
 
Core Animation
Core AnimationCore Animation
Core AnimationBob McCune
 
ios_summit_2016_korhan
ios_summit_2016_korhanios_summit_2016_korhan
ios_summit_2016_korhanKorhan Bircan
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxFlutter Agency
 
ViewController Transitions - Swift Paris Junior #3
ViewController Transitions - Swift Paris Junior #3ViewController Transitions - Swift Paris Junior #3
ViewController Transitions - Swift Paris Junior #3Julien PIERRE-LOUIS
 
Memory friendly UIScrollView
Memory friendly UIScrollViewMemory friendly UIScrollView
Memory friendly UIScrollViewYuichi Fujiki
 
Swift Animated tabBar
Swift Animated tabBarSwift Animated tabBar
Swift Animated tabBarKetan Raval
 
Celtra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra Inc
 

Ähnlich wie A short guide to animations in iOS (12)

Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
Animations - Part 2 - Transcript.pdf
Animations - Part 2 - Transcript.pdfAnimations - Part 2 - Transcript.pdf
Animations - Part 2 - Transcript.pdf
 
Core Animation
Core AnimationCore Animation
Core Animation
 
ios_summit_2016_korhan
ios_summit_2016_korhanios_summit_2016_korhan
ios_summit_2016_korhan
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptx
 
ViewController Transitions - Swift Paris Junior #3
ViewController Transitions - Swift Paris Junior #3ViewController Transitions - Swift Paris Junior #3
ViewController Transitions - Swift Paris Junior #3
 
Memory friendly UIScrollView
Memory friendly UIScrollViewMemory friendly UIScrollView
Memory friendly UIScrollView
 
Video stabilization
Video stabilizationVideo stabilization
Video stabilization
 
Swift Animated tabBar
Swift Animated tabBarSwift Animated tabBar
Swift Animated tabBar
 
iOS Core Animation
iOS Core AnimationiOS Core Animation
iOS Core Animation
 
Celtra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra builder features - Motion Graphics
Celtra builder features - Motion Graphics
 

A short guide to animations in iOS

  • 1. ANIMATIONS IN IOS Created by Anna Dovnar
  • 2. THERE ARE TWO WAYS TO WORK WITH ANIMATION. THE FIRST WAY IS VIA UIKIT, WHICH INCLUDES VIEW-BASED ANIMATIONS AS WELL AS ANIMATED TRANSITIONS BETWEEN CONTROLLERS. THE SECOND WAY IS WORKING WITH CORE ANIMATION LAYERS DIRECTLY FOR FINER-GRAINED CONTROL.
  • 3. UIKIT ANIMATION • Transitions between controllers • Transitions between views • View property animation
  • 4. VIEW CONTROLLER TRANSITIONS • CrossDissolve • CoverVertical • FlipHorizontal • PartialCurl UIVIEWCONTROLLER PROVIDES BUILT-IN SUPPORT FOR TRANSITIONING BETWEEN VIEW CONTROLLERS THROUGH THE PRESENTVIEWCONTROLLER METHOD.
  • 5. VIEW TRANSITIONS IN ADDITION TO TRANSITIONS BETWEEN CONTROLLERS, UIKIT ALSO SUPPORTS ANIMATING TRANSITIONS BETWEEN VIEWS TO SWAP ONE VIEW FOR ANOTHER.
  • 6. VIEW PROPERTY ANIMATIONS • Frame • Bounds • Center • Alpha • Transform • Color
  • 7. STARTING ANIMATIONS USING THE BEGIN/COMMIT METHODS
  • 8. STARTING ANIMATIONS USING THE BLOCK-BASED METHODS • animateWithDuration:animations: • animateWithDuration:animations:completion: • animateWithDuration:delay:options:animations:co mpletion:
  • 9. CONFIGURING THE PARAMETERS FOR BEGIN/COMMIT ANIMATIONS • setAnimationStartDate: • setAnimationDelay: • setAnimationDuration: • setAnimationCurve: • setAnimationRepeatCount: • setAnimationRepeatAutoreverses: • setAnimationDelegate: • setAnimationWillStartSelector: • setAnimationDidStopSelector: • setAnimationBeginsFromCurrentState:
  • 10. ANIMATION DELEGATE The animationID and context parameters for both methods are the same parameters that you passed to the beginAnimations:context: method at the beginning of the animation block: • animationID—An application-supplied string used to identify the animation. • context—An application-supplied object that you can use to pass additional information to the delegate. The setAnimationDidStopSelector: selector method has an additional parameter— a Boolean value that is YES if the animation ran to completion. If the value of this parameter is NO, the animation was either canceled or stopped prematurely by another animation.
  • 11. CORE ANIMATION UIVIEW ANIMATIONS ALLOW A LOT OF CAPABILITY AND SHOULD BE USED IF POSSIBLE DUE TO THE EASE OF IMPLEMENTATION. HOWEVER, SOME THINGS CANNOT BE DONE WITH UIVIEW ANIMATIONS, SUCH AS ANIMATING ADDITIONAL PROPERTIES THAT CANNOT BE ANIMATED WITH A VIEW, OR INTERPOLATING ALONG A NON-LINEAR PATH. IN SUCH CASES WHERE YOU NEED FINER CONTROL, CORE ANIMATION CAN BE USED DIRECTLY AS WELL.
  • 12. ANIMATION HAPPENS VIA LAYERS Layer animations can be either implicit or explicit
  • 13. IMPLICIT ANIMATIONS TO ADD AN IMPLICIT ANIMATION FOR THE LAYER, SIMPLY WRAP PROPERTY CHANGES IN A CATRANSACTION. THIS ALLOWS ANIMATING PROPERTIES THAT WOULD NOT BE ANIMATABLE WITH A VIEW ANIMATION
  • 14. EXPLICIT ANIMATIONS LET YOU ENCAPSULATE ANIMATIONS THAT ARE THEN EXPLICITLY ADDED TO A LAYER. THESE ALLOW FINER-GRAINED CONTROL OVER ANIMATIONS
  • 15. STOPPING AN EXPLICIT ANIMATION WHILE IT IS RUNNING • To remove a single animation object from the layer, call the layer’s removeAnimationForKey: method to remove your animation object. This method uses the key that was passed to the addAnimation:forKey: method to identify the animation. The key you specify must not be nil. • To remove all animation objects from the layer, call the layer’s removeAllAnimations method. This method removes all ongoing animations immediately and redraws the layer using its current state information.
  • 16. ANIMATIONS WITH AUTO LAYOUT • Create outlet for constraint • Change constraint.constant value • Don’t forget to call layoutIfNeeded
  • 17. ANIMATIONS IN APPLE WATCH ANIMATION IS NOT REALLY SUPPORTED
  • 18. TO MAKE SOMETHING APPEAR ANIMATED, YOU HAVE TO PRE-GENERATE A TON OF IMAGES, AND THEN CYCLE THROUGH LIKE A FLIP-BOOK. THE ERA OF THE ANIMATED GIF IS BACK! [self.imgSpriteAnimation setImageNamed:@"dragon-"]; [self.imgSpriteAnimation startAnimatingWithImagesInRange:NSMakeRange(0, 60) duration:1.0 repeatCount:0]; FOR AN EXAMPLE OF THIS, CHECK OUT APPLE’S LISTER EXAMPLE. IN THE WATCH APP’S GLANCE, YOU’LL SEE THERE ARE 360 IMAGES REPRESENTING A CIRCLE ANIMATION!