UIImageView当用户触摸它并沿顺时针方向将其手指移动时,我试图动画a 以逆时针方向旋转.
基本上我希望UIImageView一旦触摸结束就回到原来的位置,它应该以逆时针方向移动.
我遇到的问题是,每当角度(以度为单位)大于180时,图像就会顺时针旋转回原位.它显然走回了最短路径.对于179度或更小的角度,图像逆时针旋转(我需要的).
我尝试了这两段代码,它们的行为方式相同.有什么建议?
注意:这里的角度变量是一个double,它的初始值为零,在整个代码中它保持为0
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self handleObject:touches withEvent:event isLast:YES];
/* this doesn't make rotation counter clockwise for rotations greater than 180 */
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:1];
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
circle1ImgVw.transform = CGAffineTransformRotate(transform, angle);
// ends animation
[UIView commitAnimations];
/* this doesn't make rotation counter clockwise for rotations greater than 180 */
[UIView animateWithDuration:1.0 animations:^{
circle1ImgVw.transform = CGAffineTransformMakeRotation(angle);
}];
}
Run Code Online (Sandbox Code Playgroud)
我试着查看这篇文章,但它有几个问题