gpt4 book ai didi

ios - ios如何旋转控制360度

转载 作者:行者123 更新时间:2023-12-01 17:53:27 24 4
gpt4 key购买 nike

我想将控制旋转360度。我现在就那样做

#define degreesToRadians(x) (M_PI * x / 180.0)

[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.crossButton setTransform:CGAffineTransformRotate(self.crossButton.transform, degreesToRadians(360))];
} completion:nil];

但是什么也没发生。你知道我在做什么错吗?

最佳答案

360度旋转变换是恒等变换,因此
对象完全没有动画。

您可以使用“基本属性动画”获得所需的效果:

[CATransaction begin];
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.byValue = @(2 * M_PI); // 360 degrees
rotationAnimation.duration = 0.25;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.crossButton.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[CATransaction commit];

更新:如果旋转量不是360度(因此最终位置不相同)
作为初始位置),则应执行以下操作:
[CATransaction begin];
CGFloat angle = 45.0 * M_PI/180.0;
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.byValue = @(angle);
rotationAnimation.duration = 0.25;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
rotationAnimation.removedOnCompletion = YES;
[CATransaction setCompletionBlock:^{
self.crossButton.transform = CGAffineTransformRotate(self.button.transform, angle);
}];
[self.crossButton.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[CATransaction commit];

关于ios - ios如何旋转控制360度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22783517/

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