Using drawer effects in Swift projects based on MMDrawerController
// AppDelegate.swiftvar drawer = MMDrawerController()
Let leftViewController = LeftViewController () let rightViewController = RightViewController () let centerViewController = ViewController () let centerNav = UINavigationController. init (rootViewController: centerViewController) // set the Left and Right controllers to drawer = MMDrawerController. init (centerViewController: centerNav, leftDrawerViewController: leftViewController, rightDrawerViewController: rightViewController) // side distance Leave drawer. maximumLeftDrawerWidth = 0.7 * width drawer. maximumRightDrawerWidth = 0.7 * width // gesture drawer. openDrawerGestureModeMask = MMOpenDrawerGestureMode. all drawer. closeDrawerGestureModeMask = MMCloseDrawerGestureMode. all // set the animation. The transparency of the opening sidebar is set from 0 to 1 drawer. setDrawerVisualStateBlock {(drawerController, drawerSide, percentVisible)-> Void in var sideDrawerViewController: UIViewController? If (drawerSide = MMDrawerSide. Left) {sideDrawerViewController = drawerController. Rows;} if (drawerSide = MMDrawerSide. Left) {rows = drawerController. rightDrawerViewController;} sideDrawerViewController ?. View. alpha = percentVisible} self. window ?. RootViewController = drawer
In the method of clicking tableview in the left-side VC
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) } }