3

我想禁用整个视图上的用户交互,但也允许视图上的点击手势。假设主视图上方有一个菜单,如果用户再次点击主视图,后菜单就会消失。但是,只要显示菜单,就应该禁用与主视图的所有其他交互。这是我尝试这样做的方法:我像这样定义了 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 将不再工作。

预先感谢您的任何帮助。

4

2 回答 2

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;

    }
}
于 2014-04-21T10:33:08.890 回答
1

我认为不可能禁用用户交互然后期待一些用户交互事件。您可以progress bar针对特定事件显示以防止用户交互。

于 2014-04-21T10:33:05.480 回答