【问题标题】:iOS 11 - Display large title on UINavigationBar without using UINavigationControlleriOS 11 - 在 UINavigationBar 上显示大标题而不使用 UINavigationController
【发布时间】:2017-09-12 22:31:24
【问题描述】:

我有UIViewControllerUINavigationBar 作为子视图。不涉及UINavigationController

我正在尝试显示大标题。正如docs directed我们所做的那样:

myCustomNavigationBar.prefersLargeTitles = true
myCustomNavigationItem.largeTitleDisplayMode = .always

但仍停留在之前的显示模式(iOS 10 导航模式)。

使用UINavigationController 尝试相同的代码时,它会按预期工作。没有UINavigationController 是不可能的,还是我没有正确处理这个问题?

【问题讨论】:

    标签: ios uiviewcontroller uinavigationcontroller uinavigationbar uinavigationitem


    【解决方案1】:

    我不知道您在视图生命周期的哪个时间点包含这些代码行,但如果您在 viewWillAppear(_ animated: Bool) 方法中执行它们,它会完美运行。 我已经在 Xcode 9 GM 上检查过了。

    编辑:很抱歉,我没有读到您没有使用UINavigationController。没有UINavigationControllerUINavigationBar 毫无意义。请将您的UIViewController 添加到UINavigationController,如果您将这些行放在viewWillAppear(_ animated: Bool) 方法下,您会看到所需的更改

    :)

    【讨论】:

    • 尽管有很多理由不总是使用 UINavigationController。我接受了你的建议,最终它让我的架构师变得更好:)
    • 您好!当然,我并不是说您应该始终使用 UINavigationController 来处理您的应用程序上的 UIViewControllers。我刚刚说过,如果你想从一个实例化的 UIViewController 访问一个实例化的 UINavigationBar,你需要一个上面的 UINavigationController。无论如何,谢谢你的评论:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    相关资源
    最近更新 更多