swift4 使用DrawerController實(shí)現(xiàn)側(cè)滑菜單功能的示例代碼
本文介紹了swift4 使用DrawerController實(shí)現(xiàn)側(cè)滑功能的示例代碼,分享給大家,具體如下:
直接上圖

安裝
類庫(kù)開(kāi)源地址: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è)滑打開(kāi)寬度
drawerController.maximumLeftDrawerWidth = 250
// 打開(kāi)側(cè)滑手勢(shì)
drawerController.openDrawerGestureModeMask = .all
// 關(guān)閉側(cè)滑手勢(shì)
drawerController.closeDrawerGestureModeMask = .all
self.window?.rootViewController = drawerController
return true
}
Navigation上添加按鈕
icon可以在這里下載:http://www.dhdzp.com/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() {
// 打開(kāi)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)文章
Swift仿選擇電影票的效果并實(shí)現(xiàn)無(wú)限/自動(dòng)輪播的方法
這篇文章主要給大家介紹了關(guān)于Swift仿選擇電影票的效果并實(shí)現(xiàn)無(wú)限/自動(dòng)輪播的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
Swift 圖表使用Foudation庫(kù)中測(cè)量類型詳解
這篇文章主要為大家介紹了Swift 圖表使用Foudation庫(kù)中測(cè)量類型詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
switch循環(huán)所支持的數(shù)據(jù)類型案例分析
這篇文章主要介紹了switch循環(huán)所支持的數(shù)據(jù)類型,本文通過(guò)實(shí)際案例講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06
Swift UILable 設(shè)置內(nèi)邊距實(shí)例代碼
本文主要介紹Swift UILable 設(shè)置內(nèi)邊距,這里提供示例代碼供大家參考,有需要的小伙伴可以看下2016-07-07

