1

I'm working in iOS5, and apparently I should be able to control or at least subdue the UIScrollView's internal pinch gesture recognizer using scrollView.pinchGestureRecognizer.

However, my code does not seem to work. The recognizer does not treat my class as a delegate and does not wait for my rotation gesture recognizer to fail. What can I do to make the rotation gesture a priority, after which the pinch would be considered?

More precisely, the issue that I'm running in is that the view that is being rotated and zoomed at the same time "flies off the screen" towards the bottom left corner, never to be seen again.

-(void)setup scrollViews
{
        [tempScrollView.pinchGestureRecognizer requireGestureRecognizerToFail:rotationRecognizer];
        tempScrollView.pinchGestureRecognizer.delegate = self;

        tempScrollView.maximumZoomScale = 4.0;
        tempScrollView.minimumZoomScale = 0.25;
//        
        tempScrollView.delegate = self;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{

    if([gestureRecognizer isEqual:rotationRecognizer])
    {
       NSLog(@"Rotation gesture");
    }else {
        NSLog(@"Other gesture: %@", [gestureRecognizer class]);
    }
    return YES;

}

    - (IBAction)rotateView:(id)sender {

        if([sender isKindOfClass:[UIRotationGestureRecognizer class]])
        {
            UIRotationGestureRecognizer* recognizer = sender;

            float recognizerRotation = [recognizer rotation];
            CGAffineTransform transform = CGAffineTransformMakeRotation(recognizerRotation);
    activeView.transform = transform;

        }

    }
Alex Stone
  • 46,408
  • 55
  • 231
  • 407

1 Answers1

0

As far as I know, the pinchGestureRecognizer in UIScrollView is read only. However, you might try to subclass UIScrollView and override the method addGestureRecognizer: to disable the pinchGestureRecognizer, then add your own custom pinchGestureRecognizer.

iDev
  • 23,310
  • 7
  • 60
  • 85
Craig Zheng
  • 443
  • 1
  • 5
  • 17