2
votes

I have a scroll view which shows a image view. I am trying to handle UIRotationGestureRecognizer on the image view. I get the event for rotation and apply the required transform on the same. The image gets properly rotated in the scroll view. Then when I do any operations in the scroll view like zoom or pan the image rotation and position goes for a toss

_mainView is the subView of UIScrollView which is also used for zooming

UIRotationGestureRecognizer *rotationGesture=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];    
[_mainView addGestureRecognizer:rotationGesture];    
[rotationGesture release];

-(void) rotationGesture:(UIRotationGestureRecognizer *) sender {    
    if(sender.state == UIGestureRecognizerStateBegan || 
       sender.state == UIGestureRecognizerStateChanged)
    {
        sender.view.transform = CGAffineTransformRotate(sender.view.transform, 
                                                            sender.rotation);
        _currRotation = _currRotation + sender.rotation;
        [sender setRotation:0];
    }
}

I will like to understand what would be the right way to handling rotation with-in the scroll view and it maintains that rotation even after zoom events in Scroll View.

1

1 Answers

1
votes

Implement the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method in your UIGestureRecognizerDelegate, and return all gestures you want to recognize simultaneously. If you still have trouble with it, check out the answers to UIImageView Gestures (Zoom, Rotate) Question.

Good luck!

EDIT: Your comment has me guessing that the issue is that you can only have one transform on at a time, and the scroll view applies a scale transform, replacing the rotation one. You could remove the native zoom recognizer (see this question), or nest another UIView in the scroll view, and apply the rotation transform to that. I like option two, it seems easier. If you go with option one, use CGAffineTransformConcat to apply both the zoom and rotate transformations independently.