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
On your Menu view controller, add this:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
}
Then on your Menu Item View Controller, add this on viewDidLoad:
SWRevealViewController *revealController = [self revealViewController];
[revealController tapGestureRecognizer];
Also check out my answer here. It addresses the problem on front view interaction (plus a slide gesture).
Put below code on menu view controller its works for me
@interface SidebarTableViewController() {
UIView* coverView;
}
- (void)viewWillDisappear:(BOOL)animated {
[coverView removeFromSuperview];
//[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
// get your window screen size
}
- (void)viewWillAppear:(BOOL)animated {
// get your window screen size
CGRect screenRect = [[UIScreen mainScreen] bounds];
//create a new view with the same size
coverView = [[UIView alloc] initWithFrame:screenRect];
// change the background color to black and the opacity to 0.6
coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
// add this new view to your main view
[self.revealViewController.frontViewController.view addSubview:coverView];
// [self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
}
SWRevealViewController
.revealController:willMoveToPosition:
of SWRevealViewControllerDelegate
.Sample with nice animation:
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position;
{
static NSInteger tagLockView = 4207868622;
if (revealController.frontViewPosition == FrontViewPositionRight) {
UIView *lock = [self.frontViewController.view viewWithTag:tagLockView];
[UIView animateWithDuration:0.25 animations:^{
lock.alpha = 0;
} completion:^(BOOL finished) {
[lock removeFromSuperview];
}];
} else if (revealController.frontViewPosition == FrontViewPositionLeft) {
UIView *lock = [[UIView alloc] initWithFrame:self.frontViewController.view.bounds];
lock.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
lock.tag = tagLockView;
lock.backgroundColor = [UIColor blackColor];
lock.alpha = 0;
[lock addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(revealToggle:)]];
[self.frontViewController.view addSubview:lock];
[UIView animateWithDuration:0.75 animations:^{
lock.alpha = 0.333;
}];
}
}
This solution for old version 1.x SWRevealViewController.