Swift 项目中使用抽屉效果基于MMDrawerController

前端之家收集整理的这篇文章主要介绍了Swift 项目中使用抽屉效果基于MMDrawerController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

看细节请访问我的githubhttps://github.com/Zhangjingwang1993/SwiftApp
还可以点个Star,给个鼓励.
Swift/OC 进阶交流群: 498143780

// AppDelegate.swift
var drawer = MMDrawerController()
let leftViewController = LeftViewController()
        let rightViewController = RightViewController()
        let centerViewController = ViewController()
        let centerNav = UINavigationController.init(rootViewController: centerViewController)
        // 设置左右控制器
        drawer = MMDrawerController.init(centerViewController: centerNav,leftDrawerViewController: leftViewController,rightDrawerViewController: rightViewController)
        // 侧拉距离
        drawer.maximumLeftDrawerWidth = 0.7 * width
        drawer.maximumRightDrawerWidth = 0.7 * width
        // 手势
        drawer.openDrawerGestureModeMask = MMOpenDrawerGestureMode.All
        drawer.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.All
        //设置动画,这里是设置打开侧栏透明度从01
        drawer.setDrawerVisualStateBlock { (drawerController,drawerSide,percentVisible) -> Void in

        var sideDrawerViewController:UIViewController?
        if(drawerSide == MMDrawerSide.Left){
                sideDrawerViewController = drawerController.leftDrawerViewController;
            }
        if(drawerSide == MMDrawerSide.Right){
                sideDrawerViewController = drawerController.rightDrawerViewController;
            }
        sideDrawerViewController?.view.alpha = percentVisible
        }
        self.window?.rootViewController = drawer

在左侧VC中的tableview 的点击方法

func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) {
        switch (indexPath.row){
        case 0:
            let centerViewController = ViewController()
            let centerNavigationController = UINavigationController(rootViewController: centerViewController)
            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            appDelegate.drawer.centerViewController = centerNavigationController
            appDelegate.drawer.toggleDrawerSide(MMDrawerSide.Left,animated: true,completion: nil)
        default:

            let otherViewController = TestViewController()
            let otherNavigationController = UINavigationController(rootViewController: otherViewController)
            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            appDelegate.drawer.centerViewController = otherNavigationController
            appDelegate.drawer.toggleDrawerSide(MMDrawerSide.Left,completion: nil)
        }
    }

猜你在找的Swift相关文章