user5432778 user5432778 - 5 months ago 41
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?

Answer

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() {
super.viewDidLoad()
self.revealViewController().delegate = self;
 }

//YOUR CODE//

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

        }
}

//EDITED

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

//YOUR CODE//

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

I hope this help you

Comments