简体   繁体   中英

SWRevealViewController stop tap gesture when user is in frontView

I am using SWRevealViewController for sliding menu. I have added tap gesture in the front view using:

SWRevealViewController *revealController = [self revealViewController];

[revealController tapGestureRecognizer];

My tap gesture is working. But problem is that my front view has button which require the taps to navigate to other screens. IS there any way to disable the tap gesture when frontView is enabled and enable tap Gesture when menu is pressed?

I think you tried this

create the delegate on your class

@interface xxxViewController () <SWRevealViewControllerDelegate>

on delegate method as

  - (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
    if (position == FrontViewPositionLeftSide) {
        self.tapGestureRecognizer.enabled = YES;
        // disable your current class action

    }
    else if (position == FrontViewPositionLeft){
        self.tapGestureRecognizer.enabled = NO;
        // enable your current class action


    }
}

Import SWRevealViewController.h in your slide out menu class. Then in your sliding menu viewWillAppear method put this line-

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];

   self.revealViewController.frontViewController.revealViewController.tapGestureRecognizer.enabled=false;

}

and in viewWillDisappear method put this line-

-(void) viewWillDisappear:(BOOL)animated
{

self.revealViewController.frontViewController.revealViewController.tapGestureRecognizer.enabled=true;

}

In Front view controller add this

SWRevealViewController *objRevealViewController = [self revealViewController];
[self.view addGestureRecognizer:objRevealViewController.tapGestureRecognizer];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM