Sliding Menu on every view controller in swift

2019-09-13 01:42发布

问题:

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.

Here is my SlideMenuProject.zip.

My Project Screens:

回答1:

You can achieve it by 2 ways.

step 1:

Create a UIViewController with sliding menu and subclass it to as many view controllers you need sliding menu.

step 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
    }

and call each ViewController the addMenuButton() function in viewDidLoad() of ViewControllers which requires sliding menu.

hope this helps.