最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
swift4 使用DrawerController实现侧滑菜单功能的示例代码
时间:2022-06-26 05:46:34 编辑:袖梨 来源:一聚教程网
本文介绍了swift4 使用DrawerController实现侧滑功能的示例代码,分享给大家,具体如下:
直接上图
安装
类库开源地址:https://github.com/sascha/DrawerController
可惜的是,它已经不维护了,很好用的一个侧滑实现
pod 'DrawerController'
新建侧滑视图
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())) // 侧滑打开宽度 drawerController.maximumLeftDrawer// 打开侧滑手势 drawerController.openDrawerGestureModeMask = .all // 关闭侧滑手势 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 // 给导航条添加一个按钮 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. } }
相关文章
- 《三国梗传》第13关激斗长坂坡怎么通关 04-19
- 恶意不息颠覆者达拉克怎么打 04-19
- 逆水寒手游祥瑞混沌坐骑怎么获取 04-19
- 七日世界愿望机解锁方法 04-19
- 逆水寒手游1.3.2免费外观怎么获取 04-19
- 射雕丹书铁券怎么收集 04-19