我可以使用 CGAffineTransformMakeRotation 将视图旋转 360 度以上吗? [英] Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

查看:22
本文介绍了我可以使用 CGAffineTransformMakeRotation 将视图旋转 360 度以上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 iPhone 应用程序,我有一张我想要向外旋转的图像.

I'm writing an iPhone app, and I've got an image which I'ld like to have swirl outwards.

目前我的代码看起来像这样(包装在 beginAnimations/commitAnimations 块中):

Currently my code looks like this (wrapped in a beginAnimations/commitAnimations block):

scale = CGAffineTransformScale(CGAffineTransformIdentity, 5.0f, 5.0f);
swirl = CGAffineTransformRotate(scale, M_PI);
[player setTransform:swirl];    
[player setAlpha:0.0f];

但是我发现如果我尝试将旋转角度更改为 4*M_PI,它根本不会旋转.是否可以使用 CGAffineTransformRotate 获得 720° 旋转,或者我是否必须切换到其他技术?

But I find that if I try to change the angle of the rotation to, say, 4*M_PI, it doesn't rotate at all. Is it possible to get a 720˚ rotation using CGAffineTransformRotate, or do I have to switch to another technology?

如果我必须切换到另一种技术,您会建议使用另一个线程(或计时器)来自己制作动画,还是 OpenGL 是更好的选择?

If I have to switch to another technology, would you recommend using another thread (or a timer) to do the animation myself, or would OpenGL be a better route to go?

谢谢,
布莱克.

Thanks,
Blake.

推荐答案

您可以将视图旋转一定数量的弧度,无论它是小于完整旋转还是完整旋转的许多倍,而无需将旋转分成几部分.例如,以下代码将每秒旋转一次视图,持续指定的秒数.您可以轻松修改它以将视图旋转一定数量的旋转或一定数量的弧度.

You can rotate a view, by some number of radians, regardless of whether it is less than a full rotation or many multiples of a full rotation, without having to split the rotation into pieces. As an example, the following code will spin a view, once per second, for a specified number of seconds. You can easily modify it to spin a view by a certain number of rotations, or by some number of radians.

- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

这篇关于我可以使用 CGAffineTransformMakeRotation 将视图旋转 360 度以上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆