iOS以一定角度设置旋转动画

iOS以一定角度设置旋转动画,ios,animation,rotation,transform,cabasicanimation,Ios,Animation,Rotation,Transform,Cabasicanimation,我试着做一个360度旋转的视角,但是倾斜45度 像这样 我不知道该怎么做 到目前为止,我已经做到了 CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; animation.fromValue = @(0); animation.toValue = @(2 * M_PI); animation.du

我试着做一个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"];

它在y轴上旋转,但我想让y轴在旋转前倾斜45度。

1-将锚点更改为右上边缘

self.someView.layer.anchorPoint = CGPointMake(1.0, 0.5);
2-将视图旋转45或35度

CGFloat radians = (M_PI/180) * (-35);
self.someView.transform = CGAffineTransformRotate(self.someView.transform, radians);
3-按X轴旋转或翻转视图

CGFloat radians = (M_PI/180) * (180);
[UIView animateWithDuration:1 animations:^{
        self.someView.layer.transform = CATransform3DRotate(self.someView.layer.transform,radians , 1, 0.0, 0.0);

    } completion:^(BOOL finished) {
        if(finished) {
        }
    }];

就像一个符咒:)

首先,你应该看到下面的链接,它解释了“框架”和“边界”之间的区别。

现在,这是我的答案

/* 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"];
试试这个

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

CATransform3D rtfm = CATransform3DMakeRotation(2 * M_PI , 1.0f, 1.0f, 0.0f);
rtfm.m34 = -0.0015f;

animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue =   [NSValue valueWithCATransform3D:rtfm];
animation.duration = 1;

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