1

I was using SideMenu library from this github repo. https://github.com/jonkykong/SideMenu And after going high and low, I can't pinned down how to disable swipe on a navigation bar of viewcontroller.

I will use example included in library as example. At MainViewController.swift file, SideMenu is initiated and as far as I know, there are only 2 methods/functions related to gesture. And none of them are related to disable reacting to gesture. And I added this line at setUp method in the file.

SideMenuManager.default.menuPushStyle = .preserveAndHideBackButton

I have tried using childrenController in these methods but as soon as I did that, I can't use swipe/gesture on the directed view after touching on items of left sidemenu/drawer.

Is there anyway I could disable gesture on navigation bar using this library? And kindly let me know if I need to edit question, as this is my first question in stackoverflow.

Harkamal
  • 496
  • 3
  • 12
YonkaiLife
  • 53
  • 1
  • 5
  • 3
    did you checked with variable menuEnableSwipeGestures? setting its value false may work – Van Jun 07 '18 at 09:51
  • @Van I believe that variable is for enabling/disabling swipe on sideMenu/Drawer bar. And I've tested it. I want to disable swipe/gesture only on navigation bar of main viewController, and I have read the owner of repo mentioned his library hit more then 90% of use cases. So I don't want to bother him by directly mailing him. If things won't work, I might try implementing the sideMenu in DIY approach. – YonkaiLife Jun 07 '18 at 10:12
  • hide the back button of your navigation controller, with navigation swipe to go back come default – Iraniya Naynesh Jun 07 '18 at 10:57
  • @YonkaiLife can you please elaborate gesture you want to disable exactly? do you mean the right swipe gesture, which pops view controller on top? – Van Jun 07 '18 at 11:18
  • To IraniyaNaynesh SideMenuManager.default.menuPushStyle = .preserveAndHideBackButton I believe that line remove backbutton from navigation bar. @Van The way I want is like a Gmail app for iOS. if you press icon at left topmost section of the app, which is in navigation bar, the side menu will appear. And if you swipe the screen below the navigation bar from left to right, the side menu will display. But you can't swipe from navigation bar or over icon to use side menu. But now, you can swipe over icon or navigation bar in example app of SideMenu library. Let me know if you need more info. – YonkaiLife Jun 08 '18 at 02:09
  • @YonkaiLife added answer, please check, let me know if any help required – Van Jun 08 '18 at 10:28
  • @YonkaiLife did it work for you? – Van Jun 11 '18 at 09:39
  • @Van Hey, sorry for late reply. And nope, I can't fix it as of now, and I will type exact detail maybe on coming Saturday or Sunday. I mean I followed the answer and yet it doesn't work.I must admit my question needs more clarification. This is on a part of project I am working on and I need to fix other parts first. And I need to learn how formatting in stackoverflow works to type clear question/comment. I will get back asap. Thanks for help. – YonkaiLife Jun 12 '18 at 08:25

3 Answers3

0

As checked with demo example from above github project,

SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)

This line is in class 'MainViewController' in method 'setupSideMenu' which is responsible for adding pan gesture to navigation bar, which causing swipe gesture work for navigation bar. If you don't want this feature, you can simply comment the line and it will work.

Hope it helps...

Van
  • 1,225
  • 10
  • 18
0

Not sure about your scenario, but in my case when user logs out and reach on login screen i wanted to disable gesture from left to right.

At th etime user clicks on logout i set below property to 0.0 and that's it.

SideMenuManager.default.menuWidth = 0.0

Now again reset it to 85% after user re-login.

maddy
  • 4,001
  • 8
  • 42
  • 65
  • Setting the menu width to 0 seems to have no effect for me. Also, the default is 75% of the screen according to the documentation (or 240 pts, whichever is smaller). – Extragorey Oct 05 '18 at 00:24
0

I just figured out how to do this myself for a UITabBarController. The approach will be similar for a UINavigationController. I created the following function to enable/disable the swipe gestures:

/// Keeps references to the gestures created by the SideMenu manager.
private var sideMenuGestures : [UIGestureRecognizer] = []

/// Enables or disables the swipe gestures used to show a SideMenu on the given side (default: left).
func enableSideMenuGestures(_ enable: Bool, forMenu: UIRectEdge = .left) {
    if enable {
        if sideMenuGestures.count == 0 {
            sideMenuGestures.append(SideMenuManager.default.menuAddPanGestureToPresent(toView: self.tabBarController!.view))
            sideMenuGestures.append(contentsOf: SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.tabBarController!.view, forMenu: forMenu))
        }
    } else {
        self.tabBarController?.view.gestureRecognizers?.removeAll(where: { sideMenuGestures.contains($0) })
        sideMenuGestures.removeAll()
    }
}

In your case, simply replace self.tabBarController with self.navigationController and it should work the same. (The self. prefix is not required but I like to include it as a convention to show it's an inherited field rather than one I've declared.)

This works because SideMenuManager handily returns references to all the gestures it creates; otherwise you'd have to clear all gestures from the navigation controller, which would be a bad idea as explained in this answer.

Usage is then simply enableSideMenuGestures(true) in the action handler for a button which displays the menu (for example) and enableSideMenuGestures(false) when you want to disable the gestures again.

Extragorey
  • 1,654
  • 16
  • 30