Introducing Cocoa Animation

本文介绍了一种无需线程和同步的平滑动画实现方法,并探讨了动画代理如何通过查找动画字典来实现属性变化的动画效果。同时,文章还讨论了默认动画及插值的基本原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 

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

 

 

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.

 

 

三: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.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值