我想在整个视图上禁用用户互动,但也允许在视图上点击手势。假设主视图上方有一个菜单,如果用户再次点击主视图,则后面的菜单会消失。但是,只要显示菜单,就应禁用与主视图的所有其他交互。 以下是我尝试这样做的方法: 我像这样定义了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不再起作用。
提前感谢您的帮助。
答案 0 :(得分:4)
如果您在禁用用户互动的同时尝试启用tapGestureRecogizer
会有冲突,所以这是我认为最直接的解决方案:您应该做的不是关闭整个视图的用户互动对于您想要不响应触摸的每个视图。例如:
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
if (position == FrontViewPositionLeftSide) {
self.tapGestureRecognizer.enabled = YES;
self.button1.userInteractionEnabled = NO;
self.button2.userInteractionEnabled = NO;
self.tabBarController.tabBar.userInteractionEnabled = NO;
}
else if (position == FrontViewPositionLeft){
self.tapGestureRecognizer.enabled = NO;
self.button1.userInteractionEnabled = YES;
self.button2.userInteractionEnabled = YES;
self.tabBarController.tabBar.userInteractionEnabled = YES;
}
}
答案 1 :(得分:1)
我认为不可能禁用用户交互,然后期望一些用户交互事件。您可以针对特定事件显示progress bar
以阻止用户互动。