标签:
准备用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
//设置动画,这里是设置打开侧栏透明度从0到1
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
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