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!
In ViewDidLoad of your frontViewController you need to add a
UITapGestureRecognizer
This should cause the rear view to close when the front view is tapped which is
SWRevealViewController
's default behaviour.Consider this simple solution, works perfect
Simple usage in
UIViewController
:On your Menu view controller, add this:
Then on your Menu Item View Controller, add this on viewDidLoad:
Also check out my answer here. It addresses the problem on front view interaction (plus a slide gesture).