iOS动画角度旋转

时间:2014-04-17 13:58:54

标签: ios animation rotation transform cabasicanimation

我尝试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 个答案:

答案 0 :(得分:2)

首先,您应该看到下面的链接,它解释了“框架”和“边界”之间的差异。 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 :(得分: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"];

答案 2 :(得分: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) {
        }
    }];

像魅力一样工作:)

相关问题