0
votes

I am using a UIPinchGestureRecognizer to trigger the appearance of a modal UIViewController, that allows zooming and panning around an image. It essentially lets you isolate one image and explore it in more detail.

The new UIViewController has its own pinch and pan gesture recognizers.

The one downside I have noticed is that once the new UIViewController appears, the user has to take their fingers off the screen and start pinching again before the new gesture recognizer identifies the touch events.

Ideally, I would like the pinching to be seamless, so the user could continue to pinch and/or pan once the modal UIViewController appears. Is there any way to transition the touch events from the previous view controller into the modal one, in such a way the gesture recognizers in the new UIViewController are triggered?

The code that I use to trigger the modal zoom view controller:

- (IBAction)zoomImage:(UIPinchGestureRecognizer *)sender
{
    // if the gesture was released while the scale factor is sufficiently big, show the modal view
    if ( sender.state == UIGestureRecognizerStateEnded && sender.scale > 1.6f ) {
        // prepare the modal view controller
        ZoomViewController *viewControllerZoom = [[ZoomViewController alloc] initWithNibName:nil bundle:nil];
        [viewControllerZoom setImage:self.imageViewImage.image andScale:sender.scale];

        // present the modal view controller
        [self presentViewController:viewControllerZoom animated:YES completion:nil];

        // gracefully transition the image back to its original size
        [UIView animateWithDuration:0.5f animations:^{
            self.imageViewImage.transform = CGAffineTransformIdentity;
        }];
    }
    else if ( sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled ) {
        // revert to normal size on end
        [UIView animateWithDuration:0.5f animations:^{
            self.imageViewImage.transform = CGAffineTransformIdentity;
        }];
    }
    else if ( sender.scale >= 1.0f ) {
        // scale in place
        CGFloat scale = sender.scale;
        self.imageViewImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);
    }
}
2

2 Answers

0
votes

I don't think so, you would need to continue to use the existing view that the gesture is attached to and the user is already interacting with. I haven't ever tried it but I guess moving that view into the modal view controller wouldn't work. Resizing the view should work, so instead of using a modal you could change the view and add other subviews as required to provide the UI you need.

0
votes

I am not sure but do in Following way. - Make your viewcontroller (Which going to present) as delegate. - onGesture Event fire method on delegate frequently - In fired method scale or zoom your view. - Also add PinchGesture on your viewcontroller( Which going to present) and use handler for zooming and scaling purpose