xcode ENSideSwiftMenu:如何为所有视图控制器使用相同的导航栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26699138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:04:24  来源:igfitidea点击:

ENSideSwiftMenu: how to use same Navigation Bar for all View Controllers

iosxcodeuinavigationcontrolleruinavigationbaruibarbuttonitem

提问by The Nomad

I am using Evgeny Nazarov's Swift Side Menufor my iOS app and was wondering if anyone has used this same library and able to have the same Navigation Bar for every View Controllerthat is called from the menu.

我正在为我的 iOS 应用程序使用Evgeny Nazarov 的 Swift 侧边菜单,并且想知道是否有人使用过这个相同的库并且能够为View Controller从菜单中调用的每一个都拥有相同的导航栏。

I put a BarButtonItemthat toggles the sliding menu on my Root View Controller. My problem is that only my Root View Controllershows this Toggle Button. But I would like to have that same Navigation Barwith the Togglebutton on every View Controllerthat is accessible when clicking an option on the sliding menu.

BarButtonItem在我的Root View Controller. 我的问题是只有我Root View Controller显示了这个切换按钮。但是我希望在单击滑动菜单上的选项时可以访问每个按钮上Navigation BarToggle按钮View Controller

Has anyone had an experience achieving this? Thanks!

有没有人有过实现这一目标的经验?谢谢!

UPDATE 1

更新 1

This is what happens when I added a NavigationBarand BarButtonItemto the other ViewControllersthat aren't the RootViewController. The new Navigation Bar ends up under the existing Navigation Bar from the Navigation Controller.

这就是当我添加一个NavigationBarBarButtonItem另一个ViewControllers不是RootViewController. 新的导航栏最终位于导航控制器的现有导航栏之下。

The screen on the left is the Root View Controllerand the one on the right is the View Controllerwhen I select the second item on the menu.

左边的屏幕是 ,右边的屏幕Root View ControllerView Controller我选择菜单上的第二项时的屏幕。

UPDATE 2: SOLVED

更新 2:已解决

override func viewDidLoad() {
    super.viewDidLoad()

    let menuItem = UIBarButtonItem(image: UIImage(named: "icon_menu"), style: .Plain, target: self, action: "menuBarButtonItemClicked")
    menuItem.tintColor = UIColor.whiteColor()
    self.navigationItem.leftBarButtonItem = menuItem
}

func menuBarButtonItemClicked() {
    toggleSideMenuView()
}

enter image description here

在此处输入图片说明

采纳答案by evnaz

You need to put a UIBarButtonItem on the navigation bar in every view controller, not in the root view controller.

您需要在每个视图控制器的导航栏上放置一个 UIBarButtonItem,而不是在根视图控制器中。

回答by Salvatore Sepe

I too have used the same design for my app and I solved it this way: View every sect "Show the Attribute Inspector-> Top bar" the voice "Translucent Navigation Bar", then drag the "Navigation Item" and then "Bar Button Item" in the position you want. Of course every button should have its code or references to the ViewController. Let me know if you have solved.

我也为我的应用程序使用了相同的设计,我是这样解决的:查看每个部分“显示属性检查器->顶部栏”语音“半透明导航栏”,然后拖动“导航项” ,然后拖动“栏按钮” Item" 在你想要的位置。当然,每个按钮都应该有它的代码或对 ViewController 的引用。如果你解决了,请告诉我。