I am using SWRevealViewController
in order to implement a side nav menu in my app. I would like to make it so that the front view cannot be interacted with when the rear view is opened, except that when the user taps the front view, the rear view will close and the front view can be interacted with again. I have these two SWRevealViewController
delegate methods that currently remove interaction from the front view.
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition: (FrontViewPosition)position {
if(position == FrontViewPositionLeft) {
self.view.userInteractionEnabled = YES;
} else {
self.view.userInteractionEnabled = NO;
}
}
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition: (FrontViewPosition)position {
if(position == FrontViewPositionLeft) {
self.view.userInteractionEnabled = YES;
} else {
self.view.userInteractionEnabled = NO;
}
}
However this doesn't cause the rear view to close when the front view is tapped. Any help would be greatly appreciated, thanks!
If you are using SWIFT, you can do something like this, in your frontViewController:
Code works for TAP and PAN gesture.
EDIT: Change UIView's autoresizingMask to suit Swift 2, thanks to Marroc's comment
This is Swift-SWRevealViewController 2.x version of @avdyushin's answer:
I used the tapGestureRecognizer but there are still some problems. I tried this and worked great!
Define class:
Implement:
Then make your View class in Interface Builder of class IgnoreView
In your ViewController, then, do:
in - viewDidLoad
the implement in your viewcontroller also:
And you're all set!
Thanks to mixth & avdyushin for there mighty help. Here's the Swift 4 version derived from there answer to save your couple of hours:
Or you can also implement SWRevealViewControllerDelegate directly to your rear view controller class and use the SWRevealViewControllerDelegate function in the class itself.
SWRevealViewController
.revealController:willMoveToPosition:
ofSWRevealViewControllerDelegate
.Sample with nice animation:
This solution for old version 1.x SWRevealViewController.
Put below code on menu view controller its works for me