gpt4 book ai didi

iphone - 从起始角度旋转 CALayer

转载 作者:行者123 更新时间:2023-12-03 19:34:08 25 4
gpt4 key购买 nike

我想使用byValue连续旋转图层,但我无法使其正常工作。我想每秒旋转 6 度,在 60 秒内旋转一整圈。

如果图层的初始旋转为0,则一切正常。

问题是当我尝试设置初始 fromValue 时。如果我将 fromValue 设置为 90 度,动画将从 90 旋转到 90+6,然后跳转到 90+(90+6),制作动画,然后再次跳转。

有什么想法吗?

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.fromValue = [NSNumber numberWithDouble:M_PI_2];
animation.byValue = [NSNumber numberWithDouble:6.0f*M_PI/180.0f];
animation.toValue = nil;

animation.fillMode = kCAFillModeForwards;
animation.cumulative = YES;
animation.additive = NO;
animation.repeatCount = 10000;
animation.removedOnCompletion = YES;
animation.duration = 1.0;
[myLayer addAnimation:animation forKey:@"transform"];

最佳答案

这对我有用:

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath: @"transform"];
CATransform3D transform = CATransform3DMakeRotation (DegreesToRadians (90), 0, 0, 1);
animation.toValue = [NSValue valueWithCATransform3D: transform];
animation.duration = 60;
animation.cumulative = NO;
animation.repeatCount = 10000;
animation.removedOnCompletion = YES;

关于iphone - 从起始角度旋转 CALayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/943449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com