Coder Social home page Coder Social logo

Comments (3)

gresrun avatar gresrun commented on July 28, 2024

You can remove the pan gesture recognizer from the navigation controller's navigation bar for the views that you wish to disable that feature. You'll have to hold a reference to it (or recreate it) if you want to add it back later.

from ghsidebarnav.

txie avatar txie commented on July 28, 2024

Thanks, here is what I do:

  1. take pretty much everything as the sample code
  2. For the root view controller in the navigation controller, I do:
- (void)viewWillAppear:(BOOL)animated {
    // enable pan gesture
    NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
    for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
        if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
            gestureRecognizer.enabled = YES;
            break;
        }
    }
}
  1. For other view controllers (wizard-like step by step views), disable the PanGesture in viewDidLoad
    NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
    for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
        if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
            gestureRecognizer.enabled = NO;
            break;
        }
    }

It works OK, but is there any better ways?

from ghsidebarnav.

gresrun avatar gresrun commented on July 28, 2024

That seems about as simple as it can get. The only other thing I can think of is you could make it a method:

- (void)enableSwipeToRevealGesture:(BOOL)enable {
    NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
    for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
        if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
            gestureRecognizer.enabled = enable;
            break;
        }
    }
}

so it doesn't clutter your logic flow.

from ghsidebarnav.

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.