iOS以特定角度进行旋转动画

5

我正在尝试对一个视图进行360度旋转,但是倾斜角度为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度。

3个回答

2

首先,您应该查看下面的链接,了解“frame”和“bounds”之间的区别。 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"];

1

尝试一下这个;

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"];

0

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) {
        }
    }];

非常顺利地运作了 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接