在基于标签栏的应用程序上添加导航栏 [英] Adding Navigation Bar on Tab-Bar Based App

查看:26
本文介绍了在基于标签栏的应用程序上添加导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于标签栏的应用程序,我想在应用程序顶部添加导航栏.请注意,我正在使用一个名为

(顶部变得非常奇怪,模糊,PageMenu 的子标题消失了.也许它在那个模糊的东西下面,因为我仍然可以在 2 个表格视图之间滑动.

其次,我尝试删除导航控制器,并手动将导航栏添加到视图控制器.这适用于表视图和视图控制器,但不适用于 PageMenu 控制器.当我在 PageMenu Controller 上尝试时,它没有显示任何导航栏.

请注意,在 Demo 中,他们使用 Navigation Bar 作为 Parent 和 sub-TableViews,他们用这个以及 Storyboard > Navigation Controller 实现了 Navigation Bar:

override func viewDidLoad() {super.viewDidLoad()self.title = "HEADER"self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()}

最后,我试过了..

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) ->布尔{self.window = UIWindow(frame: UIScreen.mainScreen().bounds)让 nav1 = UINavigationController()让第一个 = ViewController(nibName: nil, bundle: nil)nav1.viewControllers = [第一]让第二个 = SecondViewController(nibName: "SecondViewController", bundle: nil)让 nav2 = UINavigationController()nav2.viewControllers = [第二个]让 tabs = UITabBarController()tabs.viewControllers = [nav1, nav2]self.window!.rootViewController = tabs;self.window?.makeKeyAndVisible();返回真}

但我得到的结果是:

我想要实现的目标(但使用 TabBarController;NavBar 仅用于标题):

我现在拥有的是这个.我只想像上面的 PageMenu 示例一样在它的顶部添加 NavigationBar

<小时>

更新:最后,我也尝试过:

但同样的问题:

解决方案

您还可以创建有助于解决问题的明智故事板.

在这里,我可以创建示例代码,您不需要更改单行代码,只更改故事板.

从这里下载源代码.

I have a tab-bar based app and I want to add Navigation Bar at the top of the app. Please note that I am using a library called PageMenu that creates 2 TableViews inside 1 parent ViewController.

What I tried was, adding a new ViewController and Editor->Embed in Navigation Bar. Place it before Tab Bar Controller, ctrl+drag to Tab Bar Controller to set the relationship of root view. Finally set Nav Bar Controller as initial view controller. But this fails like this:

(Top became pretty weird, blurry and the sub-header of PageMenu got disappeared. Maybe it's under that blurry thing because I can still swipe between 2 table views.

Secondly, I tried removing the Navigation Controller, and add Navigation Bar to the ViewControllers manually. This worked for table view and view controllers but not the PageMenu one. When I tried it on PageMenu Controller, it didn't show any navigation bar.

Please note that, in the Demo, they used Navigation Bar as Parent and sub-TableViews, and they achieved Navigation Bar with this as well as Storyboard > Navigation Controller:

override func viewDidLoad() {
    super.viewDidLoad()

    self.title = "HEADER"
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
  }

Lastly, I tried..

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    let nav1 = UINavigationController()
    let first = ViewController(nibName: nil, bundle: nil)
    nav1.viewControllers = [first]

    let second = SecondViewController(nibName: "SecondViewController", bundle: nil)
    let nav2 = UINavigationController()
    nav2.viewControllers = [second]

    let tabs = UITabBarController()
    tabs.viewControllers = [nav1, nav2]

    self.window!.rootViewController = tabs;
    self.window?.makeKeyAndVisible();

    return true
}

But the result I get is:

What I want to achieve (but with TabBarController; NavBar just for header):

What I have now is this. I just want to add NavigationBar at the top of it like the above PageMenu example


Update: Lasly, I also tried:

But same issue:

解决方案

You can also create like wise story board that helps to solve your problem.

Here I can created sample code what you want no single line code change but changes into storyboard only.

Download source code from here.

这篇关于在基于标签栏的应用程序上添加导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆