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

查看:522
本文介绍了我可以使用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?

谢谢,

Blake。

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天全站免登陆