gpt4 book ai didi

iOS动画旋转一个角度

转载 作者:可可西里 更新时间:2023-11-01 04:44:01 25 4
gpt4 key购买 nike

我正在尝试 360 度旋转 View ,但倾斜度为 45 度。

像这样

enter image description here

我不知道该怎么做。

到目前为止我已经做到了

CABasicAnimation* animation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation.y"];
animation.fromValue = @(0);
animation.toValue = @(2 * M_PI);
animation.duration = 1;

[self.layer addAnimation:animation forKey:@"rotation"];

它在它的 y 轴上旋转,但我想要的是这个 Y 轴在旋转之前倾斜 45 度。

最佳答案

首先,您应该看到下面的链接,其中解释了“框架”和“边界”之间的区别。 UIView frame, bounds and center

现在,这是我的答案。

/* add the 4 lines below */
self.transform = CGAffineTransformMakeRotation(M_PI_4);
self.layer.bounds = CGRectMake(0.0f, 0.0f, 60.0f, 200.0f);
self.layer.position = CGPointMake(150.0f, 300.0f);

CABasicAnimation* animation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation.y"];
animation.fromValue = @(0);
animation.toValue = @(2 * M_PI);
animation.duration = 1;

[self.layer addAnimation:animation forKey:@"rotation"];

关于iOS动画旋转一个角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135222/

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