快速在每个视图控制器上滑动菜单 [英] Sliding Menu on every view controller in swift
问题描述
当我通过单击菜单1屏幕的任何表视图行打开详细信息屏幕时,我希望第二屏幕也具有菜单1屏幕中存在的相同菜单以及用于导航至菜单1屏幕的后退按钮.即我要在我浏览的每个视图控制器中使用滑动"菜单.
When I open Detail screen by clicking on any tableview row of Menu-1 Screen, I want the Second screen to also have that same menu which is there in Menu-1 Screen and a back button for navigating to Menu-1 screen. i.e. I want the Sliding menu in every view controller that I navigate.
这是我的 SlideMenuProject.zip .
我的项目屏幕:
推荐答案
您可以通过两种方法实现它.
You can achieve it by 2 ways.
第1步:
使用滑动菜单创建 UIViewController
,并将其子类化为需要滑动菜单的视图控制器.
Create a UIViewController
with sliding menu and subclass it to as many view controllers you need sliding menu.
第2步:
您可以使用添加滑块菜单的功能来创建扩展名.然后在每个视图控制器中调用该函数.
You can create an extension with the function to add slider menu. Then call the function in each view controller.
extension UIViewController {
func addMenuButton() {
let menuButton = UIBarButtonItem.init(image: #imageLiteral(resourceName: "menu"), style: .plain, target: self, action: #selector(menuButtonAction))
navigationItem.leftBarButtonItem = menuButton
}
并在需要滑动菜单的ViewControllers的 viewDidLoad()
中调用每个ViewController的 addMenuButton()
函数.
and call each ViewController the addMenuButton()
function in viewDidLoad()
of ViewControllers which requires sliding menu.
希望这会有所帮助.
这篇关于快速在每个视图控制器上滑动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!