围绕其中心旋转UIView几次 [英] rotate a UIView around its center but several times
问题描述
我试图在它的中心周围旋转一些 UIView
,所以简单的代码像
(在伪代码中):
I'm trying to rotate some UIView
around its center, so the simple code goes something like
(in pseudocode):
[UIView beginAnimations:@"crazyRotate" context:nil];
[UIView setAnimationDuration:1.0];
someview.transform = CGAffineTransformMakeRotation(angle);
[UIView commitAnimations]
现在如果我设置角度说M_PI /很好。
如果我将其设置为2 * M_PI,它会没有。我可以理解,矩阵转换为什么都不做什么(旋转360意味着保持在某种意义上),
,但是,我想旋转它5次(认为一个报纸旋转缩放来到你效果 - 我不是很好描述,希望有人理解)。
所以,我尝试添加设置角度为180度(M_PI),并添加嵌套 animatationBlock
。
但我想,因为我设置相同的属性( someview.transition
),它会忽略它)。
我尝试将动画的重复计数设置为2,使用角度M_PI,但它似乎只是旋转180°,回到直线位置,然后再次启动旋转。
now if I set angle to say M_PI/2 the thing rotates nicely.
if I set it to 2*M_PI, well it does "nothing". I can understand that the matrix translates to something that does nothing (rotating 360 means "stay" in a sense),
yet, I want to rotate it 5 times (think of a newspaper rotate scale coming at you effect -- I'm not great at describing, hope someone understands).
So, I tried adding setting angle to 180 deg (M_PI) and add a nested animatationBlock
.
but I guess that since I'm setting the same property (someview.transition
) again it ignores it somehow).
I tried setting repeat count of the animation to 2 with angle M_PI but it seems to simply rotate 180, going back to straight position and then initiating the rotate again.
所以,我有点想法,
任何帮助赞赏!
--t
So, I'm a little out of ideas, any help appreciated! --t
推荐答案
您可以在UIView的图层属性上使用以下动画。我已经测试过了。
You can use the following animation on your UIView's layer property. I've tested it.
UIView *viewToSpin = ...;
CABasicAnimation* spinAnimation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation"];
spinAnimation.toValue = [NSNumber numberWithFloat:5*2*M_PI];
[viewToSpin.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
这篇关于围绕其中心旋转UIView几次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!