teodorpatras/SideMenuController

Disable swipe on several Controllers

Opened this issue · 10 comments

Hi,

First, congratulations for your effort, it's possible to disable the swipe gesture on several Controllers?

EXAMPLE:

HOME -> DETAIL (HERE DISABLE THE SWIPE ONLY SHOWING THE BACK BUTTON OF THE NAVIGATION BAR)

In home I want the swipe and the menu (Works perfect) but form the detail I have the back button but I don't want the swipe gesture.

Thanks

Did you found any workaround, I want to achieve the same what I want is disable the swipe feature of SideMenu for only one view controller.

Natai commented

the same to me...

I am also in need of this feature. It looks like pan/swipe can only be configured once -> globally in the static preferences structure. Updating this structure later is not changing the behaviour.

I solved it like this:

  • subclass SideMenuController
  • override its gestureRecognizer method:
open override func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if isMainControllerVisible {
        return super.gestureRecognizer(gestureRecognizer, shouldReceive: touch)
    } else {
        return false
    }
}

isMainControllerVisible (custom private property) is set to false when I set some center view controller that I don't want to have pan/swipe functionality. When I update center view controller with the "Main" controller - the controller which I want to have pan/swipe functionality - I set this flag to true.

Including @Ki1L3r issue , any way to disable the Swipe feature completely across the app ?

Yes there is!!!...
We disable/enable interactions under static property preferences
The side menu class instance keeps a lazy copy of this static object called _preferences.
You can disable interactions in your center view controller like this:

`override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
sideMenuController?._preferences.interaction.swipingEnabled = true
sideMenuController?._preferences.interaction.panningEnabled = true
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    sideMenuController?._preferences.interaction.swipingEnabled = false
    sideMenuController?._preferences.interaction.panningEnabled = false
}`

In my case I dont like changing center vc and doesnt meet my app flow so I push everytime.

Also you can call toggle() from your side bar and can access centerVC from sideMenuController extension object to push your vc.

@ajaytothenew You can do that in AppDelegate with static property as mentioned in readme file.

SideMenuController.preferences.interaction.swipingEnabled = false

I try to SideMenuController.preferences.interaction.swipingEnabled = false and it doesn't work.
Is there some reasons why it can happens?

Hi @evtaccount ,
I'm using this library in my current project and its working fine. Tell me the issue.

@evtaccount You can simply use "slideMenuController?.allowedRightSwipe = false" in specific view controller, or put it in app delegate to apply all over the project.