-->

摇曳在CABasicAnimation旋转(Flickering in CABasicAnimati

2019-10-23 11:35发布

我想从目前的角度的角度,只要按下一个按钮,旋转CAShapeLayer。

我使用的委托功能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];
}

Answer 1:

我已经解决了它提到这个博客: http://oleb.net/blog/2012/11/prevent-caanimation-snap-back/和这个答案https://stackoverflow.com/a/7690841/3902153

我不使用委托功能了。

- (IBAction)rotateBySixtyPressed:(id)sender {
    CATransform3D old_transform = self.parentLayer.transform;
    self.parentLayer.transform = CATransform3DRotate(self.parentLayer.transform, DEG2RAD(60.0), 0, 0, 1);
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D:old_transform];
    animation.duration = 3.0;
    [self.parentLayer addAnimation:animation forKey:@"transform"];
}


文章来源: Flickering in CABasicAnimation for rotation