如何减缓对象的旋转?
我有一个问题。
我有这个代码:
if(CGRectContainsPoint(compassTarcsa.frame, curLoc)) { compassTarcsaTouch = YES; float fromAngle = atan2( compassFirstLoc.y-compassTarcsa.center.y,compassFirstLoc.x-compassTarcsa.center.x ); float toAngle = atan2( curLoc.y-compassTarcsa.center.y,curLoc.x-compassTarcsa.center.x ); newAngle = (angle + (toAngle - fromAngle)); iranyFok = (newAngle / (M_PI / 180.0f)) ; if (iranyFok < 0.0f) { iranyFok += 360.0f; } iranyFok = 360-(fmodf(( 360 + iranyFok ), 360)); CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(- iranyFok)); compassTarcsa.transform = cgaRotate; repcsi.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(iranyFok));
这从0到360度旋转指南针,但旋转速度对我来说是快速的…
有人能帮我理解如何减缓这种旋转?
谢谢,
亚历克斯
尝试这个:
[UIView animateWithDuration:2.0 delay:0 options: UIViewAnimationOptionCurveEaseInOut animations:^(void){ compassTarcsa.transform = cgaRotate; } completion:NULL ];
这将把你的变换旋转包裹在一个animation中,允许你控制旋转的持续时间。
如果您想要缓慢旋转对象,您应该考虑使用旋转animation并根据您所需的速度设置其持续时间。
以下链接可能对您有所帮助:
UIView无限360度旋转animation?
http://iosdevelopertips.com/user-interface/rotate-an-image-with-animation.html
- 在生产之前,苹果沙箱用户注销
- 使用通用链接时隐藏“在应用程序中打开”横幅
- 代码签名错误:证书身份“iPhone开发人员:我的姓名(xxx)”在钥匙串中出现多次
- 设置“Content-Encoding:gzip”时,AFNetworking无法恢复下载
- 如何获取一个自定义表格视图单元格的索引path,当它的UIImage被UITapGestureRecognizer在prepareForSegue
- 如何在Swift中从图像数组中释放图像
- iOS – viewDidLoad在didFinishLaunchingWithOptions委托之前被调用?
- 当我们使用MCSessionState时,didChangeState响应非常慢,我们无法find原因
- 故事板中新视图控制器的类