这是一个奇怪的请求,但我使用核心动画(CALayers),并且我希望我的动画不稳定和不平滑。我想要一张我设置的图像,像秒针一样旋转在一个时钟上。这里是我的代码:核心动画非流畅动画
UIImage *arrowImage = [UIImage imageNamed:@"arrow.jpg"];
CALayer *arrow = [CALayer layer];
arrow.contents = (id)arrowImage.CGImage;
arrow.bounds = CGRectMake(0, 0, 169.25, 45.25);
arrow.position = CGPointMake(self.view.bounds.size.width/2, arrowImage.size.height/2);
arrow.anchorPoint = CGPointMake(0.0, 0.5);
[self.view.layer addSublayer:arrow];
CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim1.fromValue = [NSNumber numberWithFloat:0];
anim1.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
anim1.duration = 4.0;
[arrow addAnimation:anim1 forKey:@"transform"];
它会产生一个我不想要的滑动运动。我如何解决这个问题? 任何帮助表示赞赏。
感谢您的回复,虽然我听说使用CALayers会加快应用程序的性能。此外,我找到了一个我正在寻找的例子,尽管作者没有很好地解释它:http://blog.moonshine-project.com/en/2010/03/14/implicit-animation-of -custom-calayer-properties/ – 2011-01-27 23:14:37