swift4 使用DrawerController實現(xiàn)側(cè)滑菜單功能的示例代碼
本文介紹了swift4 使用DrawerController實現(xiàn)側(cè)滑功能的示例代碼,分享給大家,具體如下:
直接上圖
安裝
類庫開源地址:https://github.com/sascha/DrawerController
可惜的是,它已經(jīng)不維護(hù)了,很好用的一個側(cè)滑實現(xiàn)
pod 'DrawerController'
新建側(cè)滑視圖
import UIKit // 這個類就是一個 UIViewController 可以在里面寫任何你想寫的東西 class LeftViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.title = "Left Menu" self.view.backgroundColor = .white } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
修改 AppDelegate 類
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let drawerController = DrawerController(centerViewController: UINavigationController(rootViewController: ViewController()), leftDrawerViewController: UINavigationController(rootViewController: LeftViewController())) // 側(cè)滑打開寬度 drawerController.maximumLeftDrawerWidth = 250 // 打開側(cè)滑手勢 drawerController.openDrawerGestureModeMask = .all // 關(guān)閉側(cè)滑手勢 drawerController.closeDrawerGestureModeMask = .all self.window?.rootViewController = drawerController return true }
Navigation上添加按鈕
icon可以在這里下載:http://www.dbjr.com.cn/softs/578475.html
修改 ViewController
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.title = "DrawerDemo" self.view.backgroundColor = .white // 給導(dǎo)航條添加一個按鈕 self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "baseline-menu-48px"), style: .plain, target: self, action: #selector(ViewController.openLeftMenu)) self.navigationController?.navigationBar.barStyle = .default // menu icon默認(rèn)是藍(lán)色,下面將其改成黑色的 self.navigationController?.navigationBar.tintColor = .black } @objc func openLeftMenu() { // 打開drawerController self.navigationController?.evo_drawerController?.toggleLeftDrawerSide(animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
理解二叉堆數(shù)據(jù)結(jié)構(gòu)及Swift的堆排序算法實現(xiàn)示例
二插堆即是完全二叉樹,對于排序可以按構(gòu)建最大堆或最小堆的方式來實現(xiàn),這里我們就來共同理解二叉堆數(shù)據(jù)結(jié)構(gòu)及Swift的堆排序算法實現(xiàn)示例2016-07-07Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包
Swift引進(jìn)了閉包的概念,這個與object-c的block類似,使用過block的話都知道有多方便,所以開始學(xué)Swift,先要把閉包學(xué)會,后面使用會很頻繁。下面這篇文章主要介紹了Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03Swift編程中用以管理內(nèi)存的自動引用計數(shù)詳解
這篇文章主要介紹了Swift編程中用以管理內(nèi)存的自動引用計數(shù)詳解,是Swift入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-11-11Swift中循環(huán)語句中的轉(zhuǎn)移語句 break 和 continue
這篇文章主要介紹了Swift中循環(huán)語句中的轉(zhuǎn)移語句 break 和 continue,本文通過實例代碼給大家介紹的非常詳細(xì),需要的的朋友參考下2016-12-12LeetCode?題解?Swift?有效的完全平方數(shù)
這篇文章主要為大家介紹了LeetCode?題解?Swift?有效的完全平方數(shù)方案示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Swift自定義iOS中的TabBarController并為其添加動畫
這篇文章主要介紹了Swift自定義iOS中的TabBarController并為其添加動畫的方法,即自定義TabBarController中的的TabBar并為自定義的TabBar增加動畫效果,需要的朋友可以參考下2016-04-04