iOS Animations Flashcards
Repeating animation
.repeat: Include this option to makes your animation loop forever.
.autoreverse: Include this option only in conjunction with .repeat; this option repeatedly plays your animation forward, then in reverse.”
Animation easing
curveLinear: This option applies no acceleration or deceleration to the animation. The only time in this book you’ll use this option is in the final challenge of Chapter 3: “Transitions”.
.curveEaseIn: This option applies acceleration to the start of your animation.
.curveEaseOut: This option applies deceleration to the end of your animation.
.curveEaseInOut: This option applies acceleration to the start of your animation and applies deceleration to the end of your animation
What is spring in animation?
Spring attributes
usingSpringWithDamping: This controls the amount of damping, or reduction, applied to the animation as it approaches its final state. This parameter accepts values between 0.0 and 1.0. Values closer to 0.0 create a bouncier animation, while values closer to 1.0 create a stiff-looking effect. You can think of this value as the “stiffness” of the spring.
initialSpringVelocity: This controls the initial velocity of the animation. A value of 1.0 sets the initial velocity of the animation to cover the total distance in the span of one second. Bigger and smaller values will cause the animation to have more or less velocity, and will affect how the spring settles. Note however that the initial velocity is soon amended by the spring calculation, and the animation will always finish by the end of duration
Create transition?
AddSubview, RemoveSubview
In contrast hidding, you don’t need to worry about setting up a container view to hide and show views. In this case, the transition uses the view itself as the animation container
Replacing one view with another view with animation
To what transitions are targeted?
Transitions are targeted towards adding, removing, and replacing views in the view hierarchy.
What to “chain” animations?
use keyframes
Keyframe animations not only allow you to “chain” animations but also to “overlap” them, and group them in general in any way you wish.
Don’t forget all keyframe timing values are relative to the complete animation, whereas the API defining the complete sequence uses absolute time.”
Animating constrains from IB
- Create outlet
- Change .constant property
To animate the layout changes when you change layout programmatically
- Make change
- Call self.view.layoutIfNeeded() afterwards in animation closure
If you hadn’t called layoutIfNeeded()
UIKit would have performed a layout anyway since you changed a constraint, which marked the layout as dirty.
By calling layoutIfNeeded() from within the animation closure
you set the center and bounds of every view involved in the layout.
Views vs. layers
Layers:
A layer is a model object - it exposes data properties and implements no logic. It has no complex Auto Layout dependencies nor does it handle user interactions.
It has pre-defined visible traits - these traits are a number of data properties that affect how the contents is rendered on screen, such as border line, border color, position and shadow.
Core Animation optimizes the caching of layer contents and fast drawing directly on the GPU.
Views:
Complex view hierarchy layouts, Auto Layout, etc.
User interactions.
Often have custom logic or custom drawing code that executes on the main thread on the CPU.
Very flexible, powerful, lots of classes to subclass
Layers:
Simpler hierarchy, faster to resolve layout, faster to draw.
No responder chain overhead.
No custom logic by default. and drawn directly on the GPU.
Not as flexible, fewer classes to subclass.
If you need to choose between views and layers here is a tip:
Choose view animations any time you can to do the job; you will know when you need more performance or flexibility and have to switch to layer animations instead.
Animating the position, size, or transform of a layer equally affects
any view contained within that layer, just as if you had directly animated the view itself.