看细节请访问我的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.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)
}
}