Git Product home page Git Product logo

Comments (7)

auto234875 avatar auto234875 commented on July 18, 2024

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

from twtsidemenuviewcontroller.

onmyway133 avatar onmyway133 commented on July 18, 2024

+1

from twtsidemenuviewcontroller.

abshoff avatar abshoff commented on July 18, 2024

Please have a look at #30.

from twtsidemenuviewcontroller.

auto234875 avatar auto234875 commented on July 18, 2024

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.

from twtsidemenuviewcontroller.

abshoff avatar abshoff commented on July 18, 2024

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.

from twtsidemenuviewcontroller.

auto234875 avatar auto234875 commented on July 18, 2024

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.

from twtsidemenuviewcontroller.

onmyway133 avatar onmyway133 commented on July 18, 2024

I found RESideMenu that supports pan gesture

from twtsidemenuviewcontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.