Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not add gestures to control the open and close? #7

Open
xhzengAIB opened this issue Nov 20, 2013 · 7 comments
Open

Why not add gestures to control the open and close? #7

xhzengAIB opened this issue Nov 20, 2013 · 7 comments

Comments

@xhzengAIB
Copy link

Hi! @vokalinteractive
I think will improve the user experience

@auto234875
Copy link

You can do that by registering the navigationController interactiveGestureRecognizer to the open side menu selector.

@onmyway133
Copy link

+1

@abshoff
Copy link

abshoff commented Oct 5, 2014

Please have a look at #30.

@auto234875
Copy link

Be careful if you do this as it interferes with the interactivePopGestureRecognizer in the other viewcontroller. Meaning, if you try the back swipe gesture to pop the other viewcontrollers, it will open the side menu instead, screwing up everything.

A crude way to work around this is to delegate what the interactivePopGestureRecognizer should do in every view controller manually. Meaning, in the mainViewController, your interactivePopGestureRecognizer should open the menu. In the VC that are pushed onto the mainVC, the interactivePopGestureRecognizer carry out the action [self.navigationController popToRootViewControllerAnimated:YES];

You can do this by making the interactivePopGestureRecognizer post certain types of notifications and making every VC register to the NSNotificationCenter when it first comes onto the scene.

You also must remove the observer to these notifications right before you seque. Not doing this will cause a major bug when the user push and pop VC very fast, the app will turn completely blank. A really huge headache to implement something so simple.

@abshoff
Copy link

abshoff commented Oct 5, 2014

Thank you very much for pointing this out. I agree that there is a problem with this method if the other view controller is an instance of UINavigationController. However, in the sample project, the other view controller is an instance of UITableViewController, which, as far as I can see, does not use an interactive gesture recognizer. Thus, for the sample project, my simple changes should be fine. Please correct me if I am wrong.

Maybe one should add a navigation view controller to the sample project and give a best practice approach on how to implement these gestures. This should at least reduce headaches for anyone using this side menu controller.

@auto234875
Copy link

It's really dependent on your project. For mine, the mainVC is a UITableVC. The next VC that could get push segue are UIViewVC and UITableViewVC. You really have to worry about this if you use UINavigationController because the gesture will conflict.

To implement this, here's a sample code.
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer==self.navigationController.interactivePopGestureRecognizer) {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"popBack" object:nil];
}
return YES;

}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"popBack" object:nil];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openMenu) name:@"popBack" object:nil];
}
-(void)viewDidLoad{
self.navigationController.interactivePopGestureRecognizer.delegate=self;
}

In your other VC that will be pushed onto the UINavigationController stack,
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(anotherMethodThatPopstoRootVC) name:@"popBack" object:nil];
}

Also, don't try to get around this by making your interactivePopGestureRecognizer.delegate = nil when you segue. It just won't work and your menu will still open whenever users pop the VC.

@onmyway133
Copy link

I found RESideMenu that supports pan gesture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants