Transition gesture to a modal UIViewController
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);
}
}
No comments:
Post a Comment