dekatotoro / SlideMenuControllerSwift

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.
MIT License
3.4k stars 754 forks source link

swipe to show menu. #326

Open PrakashMaharjan opened 7 years ago

PrakashMaharjan commented 7 years ago

Hi, is there method to show menu just by swiping. Not using the left menu button? Currently it seems swiping only works when left menu is brought initially by tapping the button. The menu does not appear when swiped on view without tapping button. Any suggestion will be appreciated

Thanks

hasyapanchasara commented 7 years ago

There is a file UIViewController.swift.

If you set self.addLeftBarButtonWithImage(UIImage(named: "")!) , then side navigation drawer icon will not display and you can do open side navigation menu on swap gesture.

Also don't call toggleLeft() method manually from any UIButton action.

import UIKit

 extension UIViewController {

    func setNavigationBarItem() {
        self.addLeftBarButtonWithImage(UIImage(named: "")!)
        self.slideMenuController()?.removeLeftGestures()
        self.slideMenuController()?.removeRightGestures()
        self.slideMenuController()?.addLeftGestures()
        self.slideMenuController()?.addRightGestures()
    }

    func removeNavigationBarItem() {
        self.navigationItem.leftBarButtonItem = nil
        self.navigationItem.rightBarButtonItem = nil
        self.slideMenuController()?.removeLeftGestures()
        self.slideMenuController()?.removeRightGestures()
    }
}
PrakashMaharjan commented 7 years ago

Hi hasyapanchasara,

this --- self.addLeftBarButtonWithImage(UIImage(named: "")!) --- will lead to crash due to image nil.

I do not mean to hide the navigation drawer icon, what i want to do is be able to show the left menu by swiping. Currently, the left menu can be shown only when user taps on left navigation bar item. User is unable to bring the left menu on swipe on the main view. Is there any function for this? i.e to be able to show left menu on swipe. exacty like navigation drawer in android.

lastmboy commented 7 years ago

If I can jump in... I'm having the same issue. I have implemented this in one of my apps. I've discovered that it works perfectly when you first open the app. I have both left and right menus, and they both open with the slide motion and can be closed the same way. However, as soon as I select one of the options on the menu and open a different view controller, the sliding ability is gone. Now I can only open the menus by tapping the buttons, and they cannot be closed with a slide motion, either. If I close and stop the app, then start it again, it works perfectly until I select an option. I went back to the demo app and checked it, and it works fine, even after selecting an option. Therefore, it appears to be something in the way I have implemented it. Just wondering if your problem is similar. **Edit: Further testing determined that it's only working when on the MainViewController. If I switch to another, it stops working. When I switch back to main, it's working again. I do have the self.setNavigationBarItem() call in viewWillAppear on the other view controllers, and figured that would handle the sliding. However, it's apparently not working correctly.

lastmboy commented 7 years ago

PrakashMaharjan, I figured out the problem, at least in my case. I didn't have all my view controllers added to isTagetViewController() in ExSlideMenuController.swift. If you add in your view controllers there, it works fine.