开发者

View rotation in touchesMoved

I rotate a view by 45 degree on every drag开发者_如何学Pythonging. Here is my code. Problem here is that the view is rotated only once. After that there is no rotation. What will be the reason? Any help

  - (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];
   }


You can also use CGAffineTransformRotate to rotate from its present transform, as in:

dialView.transform = CGAffineTransformRotate(dialView.transform, 45 * M_PI / 180);


The rotation is always relative to 0. If you rotate to x several times it will rotate only the first time. If you want to rotate 45 everytime you call that code, you will need to have counter and it would look like this:

- (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];

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜