【发布时间】:2015-06-22 17:59:53
【问题描述】:
我需要UIView 的复杂连续动画,其中涉及设置需要计算的CATransform3D 旋转和平移属性,因此无法选择标准动画。
我转而使用CALayer 动画。还有这个:
self.displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(update:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- (void)update:(CADisplayLink*)sender
{
CGFloat elapsedTime = sender.timestamp - self.lastTimestamp;
self.lastTimestamp = sender.timestamp;
self.rotation += elapsedTime * 0.1; // Factor determines speed.
// This is just example for SO post; the real animation is more complicated!
CATransform3D transform;
transform = CATransform3DMakeRotation(self.rotation, 1.0, 0.0, 0.0);
self.imageLayer.transform = transform;
}
这里的self.imageLayer 是一个CALayer,它的contents 已经设置了一个图像并作为子层添加到我的基本视图中。
它确实会旋转“一点”,但不是连续旋转,有时它似乎会停止或向后旋转一点。
分配一个新的transform 似乎经常没有任何效果,因为self.rotation 的值增加了很多。添加[self setNeedsDisplay] 没有帮助。
我还没有对CALayers 做太多事情,所以我想我错过了一些非常基本的东西。试图找到它一段时间,但我找到的所有示例似乎都离我想要的太远了。
【问题讨论】:
-
@GeneratorOfOne 旋转速度必须是动画的;随着时间的推移,它必须放慢速度。那么这个方法正确吗?我应该使用
NSTimer吗?
标签: ios core-animation calayer catransform3d cadisplaylink