私は UIPinchGestureRecognizer を使用して、画像のズームとパンを可能にするモーダル UIViewController の外観をトリガーしています。基本的に、1 つの画像を分離して、より詳細に調べることができます。
新しい UIViewController には、独自のピンチおよびパン ジェスチャ レコグナイザがあります。
私が気付いた 1 つの欠点は、新しい UIViewController が表示されると、新しいジェスチャ レコグナイザーがタッチ イベントを識別する前に、ユーザーが画面から指を離してもう一度ピンチを開始する必要があることです。
理想的には、ピンチをシームレスにしたいので、モーダル UIViewController が表示されたら、ユーザーはピンチやパンを続けることができます。新しい UIViewController のジェスチャ レコグナイザーがトリガーされるように、タッチ イベントを以前のビュー コントローラーからモーダル ビュー コントローラーに移行する方法はありますか?
モーダル ズーム ビュー コントローラーをトリガーするために使用するコード:
- (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);
}
}