我想禁用整个视图上的用户交互,但也允许视图上的点击手势。假设主视图上方有一个菜单,如果用户再次点击主视图,后菜单就会消失。但是,只要显示菜单,就应该禁用与主视图的所有其他交互。这是我尝试这样做的方法:我像这样定义了 tapGestureRecognizer:
@interface GroupMasterViewController () <SWRevealViewControllerDelegate>
@property NSMutableArray *groups;
@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;
@end
在我的 ViewDidLoad 方法中,我有这个:
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.revealViewController action:@selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.tapGestureRecognizer];
self.tapGestureRecognizer.enabled = NO;
在菜单打开或关闭时触发的委托方法中:
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
if (position == FrontViewPositionLeftSide) {
self.tapGestureRecognizer.enabled = YES;
self.view.userInteractionEnabled = NO;
self.tabBarController.tabBar.userInteractionEnabled = NO;
}
else if (position == FrontViewPositionLeft){
self.tapGestureRecognizer.enabled = NO;
self.view.userInteractionEnabled = YES;
self.tabBarController.tabBar.userInteractionEnabled = YES;
}
}
问题是如果我禁用用户交互,tapGestureRecognizer 将不再工作。
预先感谢您的任何帮助。