Search code examples
iosxcodeuitabbarcontrollerswift4mmdrawercontroller

After closeing MMDrawer Controller which view controller life cycle method will called in swift4?


i have a tab bar controller, and inside that tab bar i have five view controller. i also have have a right view controller(drawer) which is on homeVC. for rightViewController i use MMDrawerController source: https://www.youtube.com/watch?time_continue=1468&v=TdKnImb4SWs. in the appdelegate . Now when the right view controller is closed, which life cycle of view controller is getting called? because i want to write a function. I have used this code on appdelegate

    let rightViewController = mainStoryboard.instantiateViewController(withIdentifier: "RightViewVC") as! RightViewVC



       UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]

    let rightSideMenuNav = UINavigationController(rootViewController: rightViewController)
    drawerController = MMDrawerController(center:mainPage,rightDrawerViewController:rightSideMenuNav)

   // drawerController!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.panningCenterView
    drawerController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView
    drawerController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.all
    drawerController!.preferredInterfaceOrientationForPresentation = MMDrawerOpenCenterInteractionMode.full

    window?.rootViewController = drawerController

Solution

  • MMDrawer provide the completion block when open,close or toggel the drawer you just need to compare the event like drawer is close or open you got the success. Here is the code

    @IBAction func rightMenuButtonTapped(_ sender: Any) { 
    
        let appdelegate = UIApplication.shared.delegate as! AppDelegate 
    
        appdelegate.drawerController?.toggle(MMDrawerSide.right, animated: true){ (isCompleted) in 
                if appdelegate.drawerController?.openSide == MMDrawerSide.none 
                { 
                     print("drawer close")
                     if let objHome = appdelegate.drawerController?.centerViewController as? HomeVC{ 
                          print("Got Home VC") 
                     }  
                } 
                else if appdelegate.drawerController?.openSide == MMDrawerSide.right 
                { 
                     print("drawer open") 
                } 
         }
    }