我正在尝试使用UIRotationGestureRecognizer
旋转视图,但问题是旋转的角度不是我视图的中心!这是我的代码:
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[rotationRecognizer setDelegate:self];
[self.view addGestureRecognizer:rotationRecognizer];
-(void)rotate:(id)sender {
if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
_lastRotation = 0.0;
return;
}
CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
CGAffineTransform currentTransform = textViews.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
_lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
[textViews setTransform:newTransform];
}
答案 0 :(得分:0)
// create and configure the rotation gesture
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureDetected:)];
[rotationGestureRecognizer setDelegate:self];
[YOUR_OBJECT_HERE addGestureRecognizer:rotationGestureRecognizer];
// YOUR_OBJECT_HERE - can be any object that you want to rotate (e.g. textView as in your case)
- (void)rotationGestureDetected:(UIRotationGestureRecognizer *)recognizer
{
UIGestureRecognizerState state = [recognizer state];
if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged)
{
CGFloat rotation = [recognizer rotation];
[recognizer.view setTransform:CGAffineTransformRotate(recognizer.view.transform, rotation)];
[recognizer setRotation:0];
}
}