Smooth Moves
you first ask mover for its animator , and you then send setFrame: to that instead.
- (void)move { if(isRight) { [[mover animator] setFrame:leftFramePosition]; } else { [[mover animator] setFrame:rightFramePosition]; } isRight = !isRight; }
animator:
The image now smoothly animates between its initial state
and the docked state.
and the docked state.
Animation with no threads and no synchronization!
二:Animation and the Animator Proxy
Finding Animations
写道
First it calls the animationForKey: method with the key that is being changed (in our example frame would be used). animationForKey:
first looks in the receiver’s animations dictionary, and if an
animation is found, it is returned. (We will eventually be adding custom
animations to this dictionary in Chapter 3, Animation Types, on
page 28.) If not, then the class method defaultAnimationForKey: is called,
and that animation is returned. The proxy then invokes the animation,
which in turn animates the change for the property.
first looks in the receiver’s animations dictionary, and if an
animation is found, it is returned. (We will eventually be adding custom
animations to this dictionary in Chapter 3, Animation Types, on
page 28.) If not, then the class method defaultAnimationForKey: is called,
and that animation is returned. The proxy then invokes the animation,
which in turn animates the change for the property.
If nil is returned from animationForKey:, then the change in the property
is not animated; instead, the value is simply passed to the underlying
object.
is not animated; instead, the value is simply passed to the underlying
object.
The default animation is a CABasicAnimation that does a basic linear
interpolation between the fromValue and the toValue. By default, the
current value of the changing property is used as the from value, and
the new value is used as the toValue for the animation. The animator
then passes responsibility to an instance of CAAnimation for doing the
interpolation between the fromValue and toValue and animating these
changes.
interpolation between the fromValue and the toValue. By default, the
current value of the changing property is used as the from value, and
the new value is used as the toValue for the animation. The animator
then passes responsibility to an instance of CAAnimation for doing the
interpolation between the fromValue and toValue and animating these
changes.
三:Animation and Interpolation
写道
The default interpolation is a straight line that starts at time zero and fromValue and finishes at the end time and toValue.
Something important to keep in mind here is that Core Animation is time-based, not frame-based.