Sidemenu: Issue/Feature Request: No way to disable only one side menu's swipe gestures

Created on 10 Jan 2017  路  7Comments  路  Source: jonkykong/SideMenu


New Issue Checklist


I have read the guidelines for contributing and I understand:

  • [x] My issue was not solved in the README.
  • [x] My issue can not be answered on stackoverflow.com.
  • [x] My issue is not a request for new functionality that I am unwilling to build and contribute with a pull request.
  • [x] My issue is reproducible in the demo project.

Issue Description

(Root Issue): menuLeftSwipeToDismissGesture is causing issues with my dynamic table and I want to disable it only for the left menu (I like the swipe-back on the right menu)

Currently:

SideMenuManager.menuEnableSwipeGestures = false

Disables ALL swipe to dismiss gestures anywhere.

Attempted various combinations of:

SideMenuManager.menuEnableSwipeGestures = false
SideMenuManager.menuLeftSwipeToDismissGesture?.isEnabled = false
SideMenuManager.menuRightSwipeToDismissGesture?.isEnabled = true

without success.

It appears handleHideMenuPan in SideMenuTransition.swift could be tweaked to allow for this functionality rather quickly by splitting menuEnableSwipeGestures > menuEnableSwipeGesturesLeft & ...Right

I can attempt this if you like, or if you'd prefer to do it yourself I'd understand. Thanks again for the great tool!

All 7 comments

Hi @RamblinWreck77, thanks for your thorough analysis.

Can you explain more about the 'issues' you're experiencing?

SideMenuManager.menuLeftSwipeToDismissGesture?.isEnabled = false should work. Note that if you have a menu being displayed by a button's action in storyboard, a new instance of the menu is instantiated each time it's tapped. This means that a new gesture is added each time, so disabling it once won't work.

The solution would be to subclass the menu and remove the gesture load, after super.viewDidLoad() is called.

Sure! Thanks for the quick reply.

Layout: Main Controller, A and B side menus (left and right)

Current situation is:

Button on main screen> func in MainController > present(A) [same for B]

A is a [subclassViewController: UITableViewController] with a dynamic table where each cell needs "swipe to delete" capability. The Issue is SideMenu's gestures override any pan gesture on the dynamic table making it impossible to delete elements of the dynamic table via swipe.

Inside A:

override func viewDidLoad() {
super.viewDidLoad()
// Menu Config
//SideMenuManager.menuLeftSwipeToDismissGesture?.isEnabled = false //didn't do anything
//SideMenuManager.menuRightSwipeToDismissGesture?.isEnabled = false //didn't do >anything
SideMenuManager.menuEnableSwipeGestures = false //does work, but once A is called B >does not have any gestures either

I even tried: including .menuEnableSwipeGestures= false/true in A/B's viewDidLoad() to switch off/on depending on which menu I was in however it appears once .menuEnableSwipeGestures is set to false anywhere it isn't switched back on in subsequent iterations of B

SideMenuManager.menuEnableSwipeGestures is a master switch for all menus, regardless of later instantiation. This isn't what you want if you only want to stop it on one side.

SideMenuManager.menuLeftSwipeToDismissGesture?.isEnabled = false works for me in the demo project in viewDidLoad of the subclass. When I say it works, I mean that the gesture to swipe the menu away has no effect as expected. If you're saying it doesn't work in some other way, you need to explain how.

Interesting. No for me it still allows me to swipe back to the main screen.

In Main:

SideMenuManager.menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as? UISideMenuNavigationController

Is how it's setup.

In main, when a button is hit it calls:

func showMenuA(){
present(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)
}

In "AviewController.swift"

class MyVehiclesTableViewController: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    //
    // Menu Config
    SideMenuManager.menuLeftSwipeToDismissGesture?.isEnabled = false

Yet somehow I can still swipe away from the left menu.... very odd. I've also verified just now that it worked in the demo and the only thing that seems to do differently is use viewWillAppear vs viewDidLoad. That didn't fix it so I'm still digging into what exactly is different about what I did...

The largest difference between my project in the demo is the Button -> function -> present() part

I found a solution, and I think it has to do with how present() in swift3 instances SideMenuManager.

/// Present A menu
func showAMenu(){
SideMenuManager.menuEnableSwipeGestures = false
present(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)
}
/// Present B Menu
func showBMenu(){
SideMenuManager.menuEnableSwipeGestures = true
present(SideMenuManager.menuRightNavigationController!, animated: true, completion: >nil)
}

This produces the desired behavior.

Is AviewController being set up as the left menu in Storyboard? Just a guess.

I'd inspect the gesture and calls at runtime to ensure that they're being set as expected and are not nil.

I'm going to close this issue but feel free to update it with more information and I'll respond as needed.

Was this page helpful?
0 / 5 - 0 ratings