码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-04-14 01:31:33      阅读:383      评论:0      收藏:0      [点我收藏+]

标签:

准备用Swift撸一个项目了, 就用这个样式了. 晚上睡不好了.黑眼圈(- -)

看细节请访问我的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.Left){
                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, animated: true, completion: nil)
        }
    }

技术分享

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

标签:

原文地址:http://blog.csdn.net/sinat_30162391/article/details/51148245

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!