顺时针旋转iOS图像
我试图通过使图像顺时针旋转并向下收缩来设置图像的动画。到目前为止,它只是逆时针运行。我尝试了沿Z旋转的值/关键点路径的正值和负值,但没有任何改变顺时针旋转iOS图像,ios,uiimageview,uianimation,Ios,Uiimageview,Uianimation,我试图通过使图像顺时针旋转并向下收缩来设置图像的动画。到目前为止,它只是逆时针运行。我尝试了沿Z旋转的值/关键点路径的正值和负值,但没有任何改变 [window addSubview:splashView]; [window bringSubviewToFront:splashView]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2.0]; [UIView se
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.frame = CGRectMake(160, 284, 0, 0);
[splashView.layer setValue:[NSNumber numberWithInt:-360]
forKeyPath:@"transform.rotation.z"];
[UIView commitAnimations];
这是因为当动画需要弧度时,您正在向动画传递度。下面是一个如何进行转换的示例
float degrees = 90.0f;
float radians = degrees * (180.0f / M_PI);
或者直接使用M_PI
=45度M_PI_4
=90度M_PI_2
=180度M_PI
=360度M_PI*2
// set transform
splashView.layer.transform = CATransform3DMakeRotation(-M_PI*2, 0, 0, 1);
而不是
[splashView.layer setValue:[NSNumber numberWithInt:-360]
forKeyPath:@"transform.rotation.z"];
要在特定方向上旋转超过360°,请使用
CAKeyframeAnimation
。在那里,您不仅可以设置最终值,还可以设置一些中间值
// consider this to be pseudo code
keyFrameAnimation.values = @[ 90, 180, 270, 360, 450, 540, ... ];
我没有任何代码给你看,但这是一种巧妙的方法。好的…………那么我应该把它放在哪里,在我的代码中设置什么设置值?@user717452你是认真的吗?我问了如何使某个东西顺时针旋转,你给了我两个浮点值,而没有其他任何东西。你想将图像旋转360度吗?我只是想知道到底旋转了多少,但是我想让它在收缩时至少旋转两次。这行代码只是让视图在不旋转的情况下收缩了。