我正在尝试旋转UIImageView360度,并在线查看了几个教程.我可以让他们都没有工作,没有UIView停止,或跳到一个新的位置.
我尝试过的最新事情是:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
Run Code Online (Sandbox Code Playgroud)
但是如果我使用2*pi,它根本不会移动(因为它是相同的位置).如果我尝试做pi(180度),它可以工作,但如果我再次调用该方法,它会向后旋转.
编辑:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
[UIView setAnimationRepeatCount:HUGE_VALF];
[UIView setAnimationBeginsFromCurrentState:YES];
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
Run Code Online (Sandbox Code Playgroud)
也不起作用.它会转到180度数,暂停一瞬间,然后在重新0开始之前重新设置为度数.
我正在写一个iPhone应用程序,我有一个想要向外旋转的图像.
目前我的代码看起来像这样(包含在beginAnimations/commitAnimations块中):
scale = CGAffineTransformScale(CGAffineTransformIdentity, 5.0f, 5.0f);
swirl = CGAffineTransformRotate(scale, M_PI);
[player setTransform:swirl];
[player setAlpha:0.0f];
Run Code Online (Sandbox Code Playgroud)
但我发现,如果我尝试将旋转角度更改为4*M_PI,它根本不会旋转.是否可以使用CGAffineTransformRotate进行720˚旋转,还是必须切换到其他技术?
如果我必须切换到另一种技术,你会建议使用另一个线程(或计时器)来自己动画,还是OpenGL会更好?
谢谢,
布莱克.
我正在尝试为iPhone开发轮盘赌游戏.如何动画(旋转)轮盘?
我将钟表臂指向12点钟到当前时间.如果是,11点,我想让手臂顺时针旋转到11点位置.但当然如果我使用:
CGAffineTransform rotation = CGAffineTransformMakeRotation(2*M_PI*11/12);
[UIView animateWithDuration:3.0
animations:^{
clockArm.transform = rotation;
}];
Run Code Online (Sandbox Code Playgroud)
旋转逆时针旋转.我试过了:
CGFloat angle = 2*M_PI*11/12;
CGAffineTransform firstRotation = CGAffineTransformMakeRotation(M_PI-0.001);
CGFloat firstRotationTime = 3.0*(M_PI/angle);
CGAffineTransform secondRotation = CGAffineTransformMakeRotation(angle);
CGFloat secondRotationTime = 3.0 - firstRotationTime;
[UIView animateWithDuration:firstRotationTime
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
self.clockArm1.transform = firstRotation;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:secondRotationTime
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
self.clockArm1.transform = secondRotation;
}
completion:^(BOOL finished){
}];
}];
Run Code Online (Sandbox Code Playgroud)
动画确实是顺时针方向,但它很不稳定 - 动画似乎仍在为第一个动画做一个UIViewAnimationEaseInOut.我做错了什么,还是有另一种方法可以实现我的目标?