每次拖动时我都会将视图旋转45度。这是我的代码。这里的问题是视图只旋转一次。之后没有轮换。会是什么原因?任何帮助
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0];
dialView.transform = CGAffineTransformMakeRotation(45* M_PI/180);
[UIView commitAnimations];
}
答案 0 :(得分:1)
您还可以使用CGAffineTransformRotate
从其现有transform
进行轮播,如下所示:
dialView.transform = CGAffineTransformRotate(dialView.transform, 45 * M_PI / 180);
答案 1 :(得分:0)
旋转始终相对于0.如果多次旋转x,它将仅在第一次旋转。 如果你想在每次调用该代码时旋转45,你需要有一个计数器,它看起来像这样:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
step++;//You are supposed to keep this variable global.
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0];
dialView.transform = CGAffineTransformMakeRotation(45*step* M_PI/180);
[UIView commitAnimations];
}