iOS Animations Flashcards

1
Q

Repeating animation

A

.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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Animation easing

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is spring in animation?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Spring attributes

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create transition?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Replacing one view with another view with animation

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To what transitions are targeted?

A

Transitions are targeted towards adding, removing, and replacing views in the view hierarchy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What to “chain” animations?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Animating constrains from IB

A
  1. Create outlet
  2. Change .constant property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

To animate the layout changes when you change layout programmatically

A
  1. Make change
  2. Call self.view.layoutIfNeeded() afterwards in animation closure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you hadn’t called layoutIfNeeded()

A

UIKit would have performed a layout anyway since you changed a constraint, which marked the layout as dirty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

By calling layoutIfNeeded() from within the animation closure

A

you set the center and bounds of every view involved in the layout.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Views vs. layers

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you need to choose between views and layers here is a tip:

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Animating the position, size, or transform of a layer equally affects

A

any view contained within that layer, just as if you had directly animated the view itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What I can animate with CGLayer?

A

Shadow
Contents
Border
Position and size

Subclasses of CALayer usually have other properties that you can animate

17
Q

Animation objects in Core Animation are

A

simply data models; you create an instance of the model and set its data properties accordingly

Since layer animations are data models that are copied by Core Animation when added to a layer, you can reuse the same model instance to create a number of similar animations and even adjust some of its properties in between adding it to different layers.

18
Q

An instance of CABasicAnimation describe

A

a potential layer animation: one that you might choose to run now, at a later time, or not at all. Since the animation isn’t bound to a specific layer, you can re-use the animation on other layers and each layer will run a copy of the animation independently. In an animation model you can specify the property to animate as the keypath argument; that’s convenient, as you’ll always be animating something in the layer.

A CABasicAnimation object is just a data model, which is not bound to any particular layer

CABasicAnimation is a basic animation model class you use to describe the desired animation, which you hand off for rendering by calling CALayer.add(_, forKey:).

19
Q

What view.layer.add(flyRight (CABasicAnimation), forKey: nil) do?

A

add(_:forKey:) makes a copy of the animation object and tells Core Animation to run it on the layer. The key argument is for your use only; it lets you identify the animation later on if you need to change or stop the animation.

add(_:forKey:) makes a copy of the animation object.

20
Q

The fillMode property

A

The fillMode property lets you control the behavior of your animation at the beginning and end of its sequence.

21
Q

Presentation layer

Animations vs. real content

A

When you animate a text field, you’re not actually seeing the field itself animated; instead, you’re seeing a cached version of it known as the presentation layer. The presentation layer is removed from the screen once the animation completes and the original layer shows itself again.

22
Q

Leaving animations on the screen

A

affects performance

23
Q

Rule for completing and setting fillMode for layers animations

A

remove your animations and consider never using fillMode, except if the effect you want to achieve is not possible otherwise. fillMode makes your UI elements lose their interactivity and also makes the screen not reflect the actual values in your layer object.

24
Q

Rule for updating layer properties

A

Consider always doing that immediately after you add the animation to your layer.

Sometimes you might get the odd flash between the initial and final animation values.
In this case, try updating your layer property to the final animation value even before adding the animation.

25
Q

CGAnimationDelegate methods

A

You can set a delegate for your layer animations and be notified whenever the animations starts or finishes.CGAnimationDelegate methods

26
Q

How to know what layer call delegate method and get this layer?

A

Set name or even reference through KVO previously
flyRight.setValue(heading.layer, forKey: "layer")

Get layer: 
`let layer = anim.value(forKey: "layer") as? CALayer`
27
Q

What value(forKey:) in animation always return?

A

Remember that value(forKey:) always returns an AnyObject?; therefore you must cast the result to your desired type. Don’t forget that the cast operation can fail, so you must use optionals in the example above to handle error conditions, such as when the name key exists but the layer key does not.

28
Q

How to control the animation after it’s been started?

A

add(_:key:) has two parameters; so far, you’ve only been using the first to pass in the animation object itself.
The key parameter is a string identifier that lets you access and control the animation after it’s been started.

29
Q

If you need to synchronize animations on a layer, then you’ll need to use

A

*animation groups*to achieve this.

30
Q

How to get exactly animation what you want from layer?

A

myViewThatIWantToAnimate.layer.add(myBasicAnimation, forKey: "animationKey") - add key

The add(_, forKey:) API allows you to optionally specify a forKey string parameter to give the particular animation a name.

Animations are key-value coding compliant so you can attach arbitrary pieces of data to give you more information about the animation’s context.

31
Q

Get all animation keys

A

` guard let runningAnimations = info.layer.animationKeys()` - get key

32
Q

Once you know which animations are running, you can do several things with them: 3 things

A
  1. Call removeAllAnimations() on the layer to stop all running animations or removeAnimation(forKey:) to remove just one.
  2. Enumerate over the list of animations returned by animationKeys(). The animation
    objects are immutable, so you can’t modify the animation while they’re in progress.
  3. Fetch an animation by key using animationForKey(_:). As before, the returned animation object will be immutable.
33
Q
A