user5432778 user5432778 - 4 months ago 27x
iOS Question

SWRevealViewController - Prevent Interacting With The Back View

When using SWRevealViewController, I do not want to let the user interact with the view that opened the side menu. Once the side menu opens, I want to just be able to interact with that menu view and not the other one.

Any help?


well I has been working with/on SWRevealViewController for a while so what you need is add your frontViewController as SWRevealViewControllerDelegate and then implementing this function

func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)

you will be notified when frontViewController go to left or to front position

this is the Swift code

in your frontViewController you need to add

class FrontViewController: UIViewController, SWRevealViewControllerDelegate
override func viewDidLoad() {
self.revealViewController().delegate = self;


func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
        if(position == FrontViewPosition.Left)
            self.view.userInteractionEnabled = true;
            self.navigationController?.navigationBar.userInteractionEnabled = true;
            self.view.userInteractionEnabled = false;
            self.navigationController?.navigationBar.userInteractionEnabled = false;



This is the Objective C code

class FrontViewController: UIViewController <SWRevealViewControllerDelegate>

in the viewDidLoad you need to add

- (void)viewDidLoad
    [super viewDidLoad];
    self.revealViewController.delegate = self;


- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
    if(position == FrontViewPositionLeft)
        self.view.userInteractionEnabled = NO;
        self.navigationController.navigationBar.userInteractionEnabled = NO;
        self.view.userInteractionEnabled = YES;
        self.navigationController.navigationBar.userInteractionEnabled = YES;

I hope this help you