最初にそのビュー コントローラーをナビゲーション コントローラーにプッシュすることにより、modalPresentationStyle
プロパティを に設定してモーダルに表示する iPad 向けのビューがあります。UIModalPresentationFormSheet
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
次に、提示されたView Controllerで、それ自体の外側でタップジェスチャを検出したいので(フォームシートとして提示したように)、タップジェスチャを次のように設定しました。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
self.tapGestureRecognizer.numberOfTouchesRequired = 1;
self.tapGestureRecognizer.numberOfTapsRequired = 1;
self.tapGestureRecognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:self.tapGestureRecognizer];
}
- (void)handleTap:(UITapGestureRecognizer*)sender
{
if (sender.state == UIGestureRecognizerStateEnded) {
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) {
[self.view.window removeGestureRecognizer:sender];
[self dismissModalViewControllerAnimated:YES];
}
}
}
私がモーダルで提示しているナビゲーション コントローラーと、そのルート ビュー コントローラーがこのジェスチャ レコグナイザーを設定するものであり、より多くのビューを階層で表示します。ルート ビュー コントローラーのみがナビゲーション コントローラー スタックにプッシュされ、その外側でタップ ジェスチャを使用すると、正しく閉じられ、このルート ビュー コントローラーを再びモーダルで表示できます。ルート ビュー コントローラーから移動し、別のビュー コントローラーをナビゲーション スタックにプッシュすると、タップ ジェスチャは機能しますが、フォーム シートを再度表示しようとするとアプリがクラッシュします。
このジェスチャと、ナビゲーション階層が必要な動作をどのように処理すればよいですか?
前もって感謝します