swift4 使用DrawerController實現(xiàn)側(cè)滑菜單功能的示例代碼
本文介紹了swift4 使用DrawerController實現(xiàn)側(cè)滑功能的示例代碼,分享給大家,具體如下:
直接上圖
安裝
類庫開源地址:https://github.com/sascha/DrawerController
可惜的是,它已經(jīng)不維護了,很好用的一個側(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可以在這里下載:https://www.jb51.net/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默認是藍色,下面將其改成黑色的
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í)有所幫助,也希望大家多多支持我們。
上一篇:Swift中的命名空間詳解
欄 目:Swift
本文標題:swift4 使用DrawerController實現(xiàn)側(cè)滑菜單功能的示例代碼
本文地址:http://www.jygsgssxh.com/a1/Swift/11940.html
您可能感興趣的文章
- 01-11swift中defer幾個簡單的使用場景詳解
- 01-11Swift開發(fā)應(yīng)用中如何更方便地使用顏色詳解
- 01-11swift4.0實現(xiàn)視頻播放、屏幕旋轉(zhuǎn)、倍速播放、手勢調(diào)節(jié)及鎖屏面
- 01-11Swift3遷移至Swift4可能遇到的問題小結(jié)
- 01-11Swift中defer的正確使用方法
- 01-11在Swift中如何使用正則表達式詳解
- 01-11Swift學(xué)習(xí)教程之SQLite的基礎(chǔ)使用
- 01-11Swift 4.2使用self做為變量名淺析
- 01-11Swift4.1轉(zhuǎn)場動畫實現(xiàn)側(cè)滑抽屜效果
- 01-11Swift如何使用類型擦除及自定義詳解


閱讀排行
本欄相關(guān)
- 01-11Swift利用Decodable解析JSON的一個小問題
- 01-11swift中defer幾個簡單的使用場景詳解
- 01-11Swift中初始化init的方法小結(jié)
- 01-11Swift中defer關(guān)鍵字推遲執(zhí)行示例詳解
- 01-11Swift利用純代碼實現(xiàn)時鐘效果實例代碼
- 01-11Swift中定義單例的方法實例
- 01-11Swift中排序算法的簡單取舍詳解
- 01-11Swift Json實例詳細解析
- 01-11Swift如何為設(shè)置中心添加常用功能
- 01-11Swift利用指紋識別或面部識別為應(yīng)用添
隨機閱讀
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 04-02jquery與jsp,用jquery
- 01-10C#中split用法實例總結(jié)


