Swift MMDrawerController 抽屉的用法

 

 

 

 

 

 

 

 

在AppDelegate.h 中设置如下

 

import MMDrawerController

 

    var window: UIWindow?

    var drawer:MMDrawerController!

 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        

        

//        let mV = MainViewController()

        let lV = LeftViewController()

        let rV = RightViewController()

        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)

        

 

    // 设置抽屉控制器 

        drawer = MMDrawerController(center: storyboard.instantiateViewController(withIdentifier: "main"), leftDrawerViewController: lV, rightDrawerViewController: rV)

        

        

        drawer.openDrawerGestureModeMask = .all

        drawer.closeDrawerGestureModeMask = .all

        

     //左右两边抽屉的宽度

        drawer.maximumLeftDrawerWidth = 300

        drawer.maximumRightDrawerWidth = 300

 

        self.window?.rootViewController = drawer

        self.window?.makeKeyAndVisible()

        return true

    }

 

 

//在MainViewController.h  中也要导入MMDrawerController。

 

    //左边按钮

    @IBAction func left(_ sender: UIButton) {

       self.mm_drawerController.toggle(MMDrawerSide.left, animated: true, completion: nil)

    }

    

 

    //右边按钮

    @IBAction func right(_ sender: UIButton) {

        self.mm_drawerController.toggle(MMDrawerSide.right, animated: true, completion: nil)

 

    }

posted @ 2017-11-03 23:17  小炮陈  阅读(919)  评论(0编辑  收藏  举报