我有一个带有一些表格和按钮的视图,然后我想在整个视图中添加一个点击手势,但我只希望该手势识别器能够识别点击。
理想情况下,我想在点击添加的手势识别器时做一些事情,然后删除该手势识别器,以便可以访问其他按钮和表格。基本上是点击关闭复制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];
}
我想让它让超级视图的识别器关闭子视图,但不干扰超级视图上的其他点击。