程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> Swift 項目中使用抽屜效果基於MMDrawerController

Swift 項目中使用抽屜效果基於MMDrawerController

編輯:JAVA綜合教程

Swift 項目中使用抽屜效果基於MMDrawerController


// 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

在左側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)
        }
    }

這裡寫圖片描述

   

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved