Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Swipe Gestures to Nil Doesn't Disable Swipe Gesture #59

Closed
mbalex99 opened this issue Aug 8, 2016 · 17 comments
Closed

Setting Swipe Gestures to Nil Doesn't Disable Swipe Gesture #59

mbalex99 opened this issue Aug 8, 2016 · 17 comments

Comments

@mbalex99
Copy link
Contributor

mbalex99 commented Aug 8, 2016

        conversationsViewController.conversationsViewControllerDelegate = self
        SideMenuManager.menuLeftNavigationController = conversationsViewController
        SideMenuManager.menuPresentMode = .ViewSlideInOut
        SideMenuManager.menuFadeStatusBar = false
        SideMenuManager.menuWidth = max(round(min(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) * 0.85), 240)
        SideMenuManager.menuShadowOpacity = 0
        SideMenuManager.menuRightSwipeToDismissGesture = nil
        SideMenuManager.menuLeftSwipeToDismissGesture = nil
        SideMenuManager.menuAnimationPresentDuration = 0.25
        SideMenuManager.menuAnimationDismissDuration = 0.25

As you can see I've set both swipe gestures to nil however, I'm still able to swipe and dismiss the controller. What am I doing wrong?

@jonkykong
Copy link
Owner

@mbalex99, dig a little deeper! Both menuRightSwipeToDismissGesture and menuRightSwipeToDismissGesture are weak references, so that should be a clue that setting to nil won't release them.

You need to either remove the gestures from the view or disable them. Read up on UIGestureRecognizers for more info.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 8, 2016

Hmm it didn't seem to work.

I tried this:

SideMenuManager.menuRightSwipeToDismissGesture?.enabled = false
SideMenuManager.menuLeftSwipeToDismissGesture?.enabled = false

and even on this on both the side viewcontroller and the main viewcontroller

if let swipe1 = SideMenuManager.menuRightSwipeToDismissGesture, swipe2 = SideMenuManager.menuLeftSwipeToDismissGesture {
            view.removeGestureRecognizer(swipe1)
            view.removeGestureRecognizer(swipe2)
        }

The swiping still seems to occur.

@jonkykong
Copy link
Owner

You can't disable it if you set the reference to nil. Also I think the gesture is recreated every time the menu is exposed. Take a look at the code to understand more closely.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 8, 2016

Thanks for the quick replies.

  1. I removed the lines of code that set it to nil, so they're actually caught by the if let blocks
  2. I've put these the disabling of code within viewDidAppear and they seem to be properly disabled.

I'm taking a look at the code right now and I can't seem to figure out why the gestures are still being fired.

@jonkykong
Copy link
Owner

Try removing them in viewDidAppear if disabling isn't working.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 8, 2016

I created a test project here. I think either this is a bug or I'm obviously missing something.
https://github.com/mbalex99/swipesidemenuissue
The swipe still occurs.

@jonkykong
Copy link
Owner

There is still more to try before calling this a bug.

Your code has you disabling it in viewDidLoad. My guess is that inspecting the gestures at that point would reveal they are nil, so that won't work.

In menuPressed you have it disabling the gestures. Again inspection may reveal that the gestures at that point are still nil since the menu hasn't revealed yet.

Instead, in MenuViewController, try disabling or removing the gestures on viewWillAppear.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 8, 2016

https://github.com/mbalex99/swipesidemenuissue

I pushed those changes and added some explicit code.

Okay I did what you said, doesn't seem to be working. I checked and the gestures are never nil at viewDidLoad or viewWillAppear or viewWillAppear

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 8, 2016

So yeah I've tried everything and it's still swiping. If it's this difficult or unintuitive wouldn't that be respectable to say it's a bug by now?

Again thanks for swift support! 👍

@jonkykong
Copy link
Owner

Disabling them in viewWillAppear of the menu is working for me.

However, it's important to note that it's disabling those gestures on the menu itself, but not on the main screen that's partially displayed. The main screen has a transparent view over it to take taps and swipes to hide the menu and prevent the partial screen from being interacted with. The gestures were separated this way so that they could be disabled on the menu in case of special menu gestures but still make it easy to dismiss the menu. As such, this is not a bug, but by design.

As a general note, my goal with this library was to hit the 90%+ use case, and I think it's accomplished that. If you would like to contribute to this library, I'm all for it! I haven't heard of a compelling use case for turning off the swiping gestures from anyone else yet.

If you want to contribute, I would suggest taking a look at line 310 of SideMenuTransition. These are the gestures you would like to disable, but they are not exposed. There would either need to be a boolean added to SideMenuManager to turn off swipe gestures at large, or a getter method to expose those gestures to be disabled.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 9, 2016

Are you using the same code from my project? I have the code in the MenuViewController at viewWillAppear and you can still swipe to dismiss.

Ah I see what you did there with the transparent overlay, but since the SideMenuManager is managing a singleton instance shouldn't the disable/enable of the gesture recognizers still disable it for all instances?

@jonkykong
Copy link
Owner

I added two lines of code to disable gestures to the example project in the repo and it worked as expected.

A challenge with the design is that a storyboard will create a new instance of a SideMenu via segues, vs. setting up the right and left menus on first launch. Since a new menu instance can be created at any time, many of the commands related to menus are not singleton oriented, but hooked to the singular instance of that menu when its assigned to the manager. It could be re-architected to move the gesture from menu to menu or use a master boolean to control behavior, but again in light of the 90%+ use cases there was no need for that level of effort.

@mbalex99
Copy link
Contributor Author

mbalex99 commented Aug 9, 2016

Okay! I created a fork and a pull request!

@jonkykong
Copy link
Owner

@mbalex99 I don't see any pull requests.

@jonkykong
Copy link
Owner

@mbalex99 disregard just appeared.

@o15a3d4l11s2
Copy link

I would also like to see this feature implemented. Looking forward to the pull request merged.

@jeanraymonddaher
Copy link

its here 👍
sideMenuNavigationController.enableSwipeToDismissGesture = false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants