Question

I would like to disable the user interaction on the entire view but also allow the tap gesture on the view. Let say there is a menu above the main view and if the user taps on the main view again the rear menu disappears. However all other interaction with the main view should be disabled as long as the menu is shown. Here is how I try to do that: I defined the tapGestureRecognizer like this:

@interface GroupMasterViewController () <SWRevealViewControllerDelegate>

@property NSMutableArray *groups;
@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;

@end

In my ViewDidLoad method I have this:

self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.revealViewController action:@selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.tapGestureRecognizer];
self.tapGestureRecognizer.enabled = NO;

And in the delegate method which gets fired when the menu opens or closes:

- (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;

    }
}

The Problem is that the tapGestureRecognizer does not work anymore if I disable the user interaction.

Thank you in advance for any help.

Was it helpful?

Solution

It would be conflict if you try to enable tapGestureRecogizer while disabling user interaction, so this is the most straight-forward solution in my honest opinion: Instead of turning off user interaction of the whole view, you should do that to each of the views that you want to not response to touches. For example:

- (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;

    }
}

OTHER TIPS

I think it is not possible to disable user interaction and then expect some user interaction events. You may show progress bar for a particular event to prevent user interaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top