2009-10-12 70 views
1

我在每次拖动时将视图旋转45度。这是我的代码。这里的问题是视图只旋转一次。之后,没有旋转。原因是什么?任何帮助在touchesMoved中查看旋转

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

旋转总是相对于0。 如果要旋转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]; 

}

1

您还可以使用CGAffineTransformRotate从目前的transform旋转,如在:

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