いくつかのテーブルとボタンを含むビューがあり、ビュー全体にタップ ジェスチャを追加したいのですが、そのジェスチャ レコグナイザーにタップを認識させるだけです。
理想的には、追加されたジェスチャ認識エンジンがタップされたときに何かを行い、その後そのジェスチャ認識エンジンを削除して、他のボタンやテーブルにアクセスできるようにしたいと考えています。基本的には、Facebook の通知ウィンドウのような機能を複製する機能を閉じるためのタップです。閉じるには外側をタップしますが、通知ビューの外側のボタンには干渉しません。
誰でも助けることができますか?
私の現在のコードは次のとおりです。
NotificationsWindow *customView = [[[NSBundle mainBundle]loadNibNamed:@"NotificationsWindow" owner:self options:nil]objectAtIndex:0];
customView.frame= CGRectMake(12, 12, customView.frame.size.width, customView.frame.size.height);
UITapGestureRecognizer *recognizerForSubView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehindAgain:)];
[recognizerForSubView setNumberOfTapsRequired:1];
recognizerForSubView.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
[customView addGestureRecognizer:recognizerForSubView];
[self.view addSubview:customView];
[self catchTapForView:customView.superview];
(void)handleTapBehind:(UITapGestureRecognizer *)sender
{
NSLog(@"tapped");
[[self.view.subviews lastObject] removeFromSuperview];
[self.view removeGestureRecognizer:sender];
}
(void)dismissButton:(UIButton *)button {
[button removeFromSuperview];
[[self.view.subviews lastObject] removeFromSuperview];
}
(void)catchTapForView:(UIView *)view {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = view.bounds;
[button addTarget:self action:@selector(dismissButton:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
}
スーパー ビューのレコグナイザーがサブビューを閉じるようにしたいが、スーパー ビューの他のタップを妨げないようにしたい。