如何使用故事板隐藏 UINavigationController 的工具栏? [英] How can I hide the toolbar of a UINavigationController using storyboards?

查看:40
本文介绍了如何使用故事板隐藏 UINavigationController 的工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板 iOS 应用程序,其中包含我推送的许多视图.我有一个 UINavigationController 选择了显示工具栏"选项,然后填充到我的整个视图层次结构中.

I have a storyboard iOS app that has a number of views I push through. I have a UINavigationController with the "Shows Toolbar" option selected, which then populates throughout my view hierarchy.

假设我的视图流是 3 个视图,A、B 和 C:

Say my view flow is 3 views, A, B, and C:

View A --(push)--> View B --(push)--> View C

View A 是一个普通的视图控制器,工具栏上有一个按钮用于推送 View B.View B 是一个表格控制器,所以我想在这里隐藏工具栏.视图 C 是另一种与视图 A 类似的视图,需要显示一个工具栏.

View A is a normal view controller, with a button on the toolbar used to push View B. View B is a table controller, so I want to hide the toolbar here. View C is another view like View A, with a toolbar required to be shown.

在 Xcode/Storyboard 中,如果在 View BI 中选择Hides bottom bar on push",它就是这样做的 - View B 的底部栏是隐藏的.同样,如果我为Bottom bar"选择选项选择None",B 景没有酒吧.很好.

In Xcode/Storyboard, if in View B I select the "Hides bottom bar on push" it does exactly that - the bottom bar is hidden for View B. Similarly if I choose 'None' for the 'Bottom bar' select option, there's no bar for View B. Good.

这是我的问题:无论我做什么,使用视图 B 的任一选项,我的工具栏都不会返回视图 C.如果我将视图 C 的工具栏设置为推断(并取消选中隐藏推送),它不会显示,如果我手动将其设置为工具栏".

Here's my problem: No matter what I do, using either option for view B, my toolbar doesn't come back for view C. If I set View C's toolbar as inferred (and uncheck hide on push) it doesn't show, nor if I set it manually to 'Toolbar'.

有什么想法吗?

推荐答案

正如@Zoltán 所说,Storyboard 没有提供完整的答案.

As @Zoltán said, Storyboard doesn't provide the complete answer.

在 viewDidLoad 或 viewWillAppear 上设置 self.navigationController.toolbarHidden = YES/NO 是有效的,但很难看(在视图转换动画期间,工具栏出现黑色矩形).

Setting self.navigationController.toolbarHidden = YES/NO on viewDidLoad or viewWillAppear is functional, but ugly (a black rectangle appears in place of the toolbar during the view transition animation).

这是我为 View B 控制器(以及 View C 的逆控制器)所做的,以模仿故事板中隐藏时隐藏"选项的动画平滑度:

Here's what I did for the View B controller (and the inverse for View C) to mimic the animation smoothness of the "hide on push" option in the storyboard:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:YES];
}

这篇关于如何使用故事板隐藏 UINavigationController 的工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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