【发布时间】:2014-07-19 07:35:38
【问题描述】:
我目前正在实现一个 CABasicAnimation 动画 CALayer transform 属性。
现在,虽然我是 Core Animation 的新手,但我已经能够通过各种博客和文章(例如 objc.io)收集到,使用经常(错误地)推荐的方法来使用fillMode 和 removedOnCompletion 动画的属性。这种方法被许多人认为是不好的做法,因为它会在模型层和表示层之间产生差异,因此未来对其中一个层的查询可能与用户所看到的不匹配。
相反,推荐的制作动画的方法是在将动画添加到动画层的同时更新模型层。但是,我无法准确理解这是如何工作的。我的动画很简单,如下所示:
CATransform3D updatedTransform = [self newTransformWithCurrentTransform];
// Location 1
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.duration = 1;
transformAnimation.fromValue = [NSValue valueWithCATransform3D:self.layerBeingAnimated.transform]; // Does not work without this.
transformAnimation.toValue = [NSValue valueWithCATransform3D:updatedTransform];
// Location 2
[self.layerBeingAnimated addAnimation:transformAnimation forKey:kTransformAnimationKey];
// Location 3
我已经指出了三个我尝试使用代码更新模型层的位置
self.layerBeingAnimated.transform = updatedTransform;
在位置 1,图层直接跳转到 newTransform 并且没有动画。
在位置 2,图层的动画效果完全符合我的要求,从当前变换到 newTransform。
在位置 3,图层直接跳到 newTransform,跳回旧变换,正确地从 fromValue 动画到 newTransform,然后停留在 newTransform。
这里有什么问题?更新模型层的正确位置是什么?为什么这三个位置会产生如此不同的结果?
谢谢!
【问题讨论】:
-
我喜欢你们都完成了阅读,自己进行了实验,并写了一个明确的问题!
标签: ios iphone core-graphics core-animation calayer