swift4 使用DrawerController實(shí)現(xiàn)側(cè)滑菜單功能的示例代碼
本文介紹了swift4 使用DrawerController實(shí)現(xiàn)側(cè)滑功能的示例代碼,分享給大家,具體如下:
直接上圖
安裝
類庫開源地址:https://github.com/sascha/DrawerController
可惜的是,它已經(jīng)不維護(hù)了,很好用的一個(gè)側(cè)滑實(shí)現(xiàn)
pod 'DrawerController'
新建側(cè)滑視圖
import UIKit // 這個(gè)類就是一個(gè) 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è)滑手勢(shì) drawerController.openDrawerGestureModeMask = .all // 關(guān)閉側(cè)滑手勢(shì) drawerController.closeDrawerGestureModeMask = .all self.window?.rootViewController = drawerController return true }
Navigation上添加按鈕
icon可以在這里下載:http://chabaoo.cn/softs/578475.html
修改 ViewController
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.title = "DrawerDemo" self.view.backgroundColor = .white // 給導(dǎo)航條添加一個(gè)按鈕 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. } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
理解二叉堆數(shù)據(jù)結(jié)構(gòu)及Swift的堆排序算法實(shí)現(xiàn)示例
二插堆即是完全二叉樹,對(duì)于排序可以按構(gòu)建最大堆或最小堆的方式來實(shí)現(xiàn),這里我們就來共同理解二叉堆數(shù)據(jù)結(jié)構(gòu)及Swift的堆排序算法實(shí)現(xiàn)示例2016-07-07Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包
Swift引進(jìn)了閉包的概念,這個(gè)與object-c的block類似,使用過block的話都知道有多方便,所以開始學(xué)Swift,先要把閉包學(xué)會(huì),后面使用會(huì)很頻繁。下面這篇文章主要介紹了Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03Swift編程中用以管理內(nèi)存的自動(dòng)引用計(jì)數(shù)詳解
這篇文章主要介紹了Swift編程中用以管理內(nèi)存的自動(dòng)引用計(jì)數(shù)詳解,是Swift入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-11-11Swift中循環(huán)語句中的轉(zhuǎn)移語句 break 和 continue
這篇文章主要介紹了Swift中循環(huán)語句中的轉(zhuǎn)移語句 break 和 continue,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的的朋友參考下2016-12-12Swift中風(fēng)味各異的類型擦除實(shí)例詳解
你也許曾聽過類型擦除,甚至也使用過標(biāo)準(zhǔn)庫提供的類型擦除類型如 AnySequence,下面這篇文章主要給大家介紹了關(guān)于Swift中風(fēng)味各異的類型擦除的相關(guān)資料,需要的朋友可以參考下2022-04-04LeetCode?題解?Swift?有效的完全平方數(shù)
這篇文章主要為大家介紹了LeetCode?題解?Swift?有效的完全平方數(shù)方案示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Swift自定義iOS中的TabBarController并為其添加動(dòng)畫
這篇文章主要介紹了Swift自定義iOS中的TabBarController并為其添加動(dòng)畫的方法,即自定義TabBarController中的的TabBar并為自定義的TabBar增加動(dòng)畫效果,需要的朋友可以參考下2016-04-04