iOS动画角度旋转

Mar*_*ges 5 animation transform rotation cabasicanimation ios

我正在尝试360度旋转视角,但倾斜度为45度.

像这样

在此输入图像描述

我无法想办法做到这一点.

到目前为止,我已经成功了

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

[self.layer addAnimation:animation forKey:@"rotation"];
Run Code Online (Sandbox Code Playgroud)

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

ryu*_*aki 2

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

现在,这是我的答案。

/* 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"];
Run Code Online (Sandbox Code Playgroud)