1
我想旋转CAShapeLayer从当前角度角度每当按钮被按下。闪烁CABasicAnimation旋转
我使用委托函数animationDidStop在动画结束时设置图层的转换,因为我注意到动画只改变了表示层的转换,而不是本身的图层。
但动画中存在随机闪烁,在动画完成时,似乎在动画结束时,由于图层在委托函数animationDidStop中更新变换之前返回到其先前变换。我如何消除闪烁?
@implementation ViewController
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
[CATransaction begin];
[CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions];
self.parentLayer.transform = CATransform3DRotate(self.parentLayer.transform, DEG2RAD(60.0), 0, 0, 1);
[CATransaction commit];
}
- (IBAction)rotateBySixtyPressed:(id)sender {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.duration = 3.0;
animation.byValue = [NSNumber numberWithFloat:DEG2RAD(60.0)];
[animation setDelegate:self];
[self.parentLayer addAnimation:animation forKey:animation.keyPath];
}