jonkykong / SideMenu

Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.
MIT License
5.67k stars 693 forks source link

Pushed viewcontroller appeared in the sidemenu controller #601

Closed mEldewaik closed 4 years ago

mEldewaik commented 4 years ago

I have read the guidelines for contributing and I understand

Describe the bug A clear and concise description of what the bug is. i have a sidemenu in my project it presented as expected. i have a button in my sidemenu and when i make push to new viewcontroller it pushed but in the viewcontroller of sidemenu

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen. i expect that the sidemenu disapeared and a new view controller pushed but i have the new viewcontoller in the same sidemenu controller

Screenshots If applicable, add screenshots to help explain your problem. Image from iOS (2) Image from iOS (3)

Additional context Add any other context about the problem here.

`@IBAction func editProfileBtnPressed(_ sender: UIButton) {
    if let vc = UIStoryboard(name: "ProvProfile", bundle: nil).instantiateViewController(withIdentifier: "ProviderProfileVC") as? ProviderProfileVC {
        self.navigationController?.pushViewController(vc, animated: true)
    }
}`
`@IBAction func menuBtnPressed(_ sender: UIBarButtonItem) {

    if let rightMenu = SideMenuManager.default.rightMenuNavigationController {
        present(rightMenu, animated: true, completion: nil)
    }
}`

`class func makeSettings() -> SideMenuSettings {
        let presentationStyle: SideMenuPresentationStyle = .menuSlideIn
        presentationStyle.backgroundColor = .clear

        var settings = SideMenuSettings()
        settings.presentationStyle = presentationStyle
        settings.menuWidth = UIScreen.main.bounds.width * 0.75
        settings.alwaysAnimate = true
        settings.usingSpringWithDamping = 0.9
        settings.blurEffectStyle = .regular
        settings.statusBarEndAlpha = 0
        settings.dismissOnPush = true
        return settings
    }

    class func setupSideMenu(storyBoard: UIStoryboard,_ viewcontroller: UINavigationController) {
        let menu = storyBoard.instantiateViewController(withIdentifier: "SideMenu") as? 
SideMenuNavigationController

        SideMenuManager.default.rightMenuNavigationController?.settings = 
HelperMethods.makeSettings()
        SideMenuManager.default.rightMenuNavigationController = menu
        SideMenuManager.default.addPanGestureToPresent(toView: viewcontroller.navigationBar)
        SideMenuManager.default.addScreenEdgePanGesturesToPresent(toView: viewcontroller.view)

}`
naveen204pauly commented 4 years ago

@mEldewaik You can't push a controller from the presented view controller. So make sure your main view controller which is going to show your side menu view controller should be embedded in a Navigation controller.

This piece of code works fine because the navigation controller is embedded in window

` self.window = UIWindow.init(frame: UIScreen.main.bounds)

    let navigationController = UINavigationController.init()

    let mainView = UIStoryboard.init(name: UserManager.isLoggedIn ? "Main" : "Login",
                                     bundle: Bundle.main).instantiateInitialViewController()!

    navigationController.viewControllers = [mainView]

    self.window?.rootViewController = navigationController`

Without the navigation controller as root, I can experience the same issue as you described

` self.window = UIWindow.init(frame: UIScreen.main.bounds)

    let mainView = UIStoryboard.init(name: UserManager.isLoggedIn ? "Main" : "Login",
                                     bundle: Bundle.main).instantiateInitialViewController()!

    self.window?.rootViewController = mainView

`

jonkykong commented 4 years ago

Please follow the README instructions carefully.

Dave181295 commented 3 years ago

Stuck hours with this, give us a real example with the storyBoard please

Dave181295 commented 3 years ago

what if I got a login screen and want to redirect user if hes signed in directly to the main screen (the vc that present the sideMenu) ?