我可以在没有CALayers的情况下使用Core Animation吗?
问题描述:
是否可以使用Core Animation来改变CALayers的其他属性?我想用一个简单的属性动画来缓解我的模型类上的值。事情是这样的:我可以在没有CALayers的情况下使用Core Animation吗?
CABasicAnimation* anim = [CABasicAnimation animation];
anim.keyPath = @"someProperty";
anim.fromValue = [NSNumber numberWithFloat: 0.0];
anim.toValue = [NSNumber numberWithFloat: 1.5];
anim.duration = 1.0;
anim.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
然后调用类似[anim update]
直到动画完成。
答
图层类(CALayer及其子类)是Core Animation的基础。这些类提供显示内容。所以,不,你不能在没有使用CALayers的情况下使用Core Animation。
我建议通过Apple's description of Core Animation来阅读。根据你所描述的,你想使用核心动画类CABasicAnimation来通知你的模型类在动画的持续时间内应该有一个特定的值。核心动画的类不是用于这种方式的,或者与核心动画框架以外的任何其他类型一起使用。
你真正想要的是一个类/库,它可以为你提供从纯粹数学的角度而不是动画的值之间的定时插值。也许有一些开源代码可以为你做到这一点。
答
可以使用在CALayer上运行的CABasicAnimation,而不使用CALayer本身;但要查询它的 - (id)presentationModel。人们甚至可以将自己的密钥添加到以这种方式进行动画制作的CALayer