iOS 11大标题导航栏未折叠 [英] iOS 11 large-title navigation bar not collapsing

查看:163
本文介绍了iOS 11大标题导航栏未折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可可触摸WWDC视频中的新内容中的苹果人新的大标题导航栏将神奇地挂接到基础视图控制器的顶级滚动视图中,并在上下滚动时自动折叠/扩展自身. (神奇地",他可能意味着他们无法以一种可用的方式将这一功能猴子化到已经令人尴尬的UINavigationController-UINavigationBar-UINavigationitem API中,因此,他们不得不求助于某些启发式选择幕后滚动视图)

The Apple guy in the What's new in Cocoa Touch WWDC video said that the new large-title navigation bar will magically hook into the top-level scroll view of the underlying view controller and collapse/expand itself automatically while scrolling up and down. (And by "magically", he probably meant that they failed to monkey patch this functionality into the already embarassing UINavigationController-UINavigationBar-UINavigationitem APIs in a usable way, so they had to resort to hooking into some heuristically chosen scroll view behind the scenes)

即使我准备好如果我稍微偏离基本的UINavigationController + UITableView/UICollectionView设置,这种自动"折叠/展开也不起作用,即使在这种最简单的情况下,它似乎也不会不能按预期工作.

Even though I was prepared that this "automatic" collapse/expand wouldn't work if I deviate the slightest from the basic UINavigationController + UITableView/UICollectionView setup, it seems that even in this simplest case it doesn't work as expected.

这就是我所拥有的:

包含UINavigationControllerUITabBarController,其中包含UIViewControllerUIViewController作为其view.点击表中的第一个单元格将在导航堆栈中推送第二个视图控制器:

A UITabBarController which contains a UINavigationController, which contains a UIViewController, which has a UITableView as its view. Tapping the first cell in the table will push a second view controller on the navigation stack:

没有代码,只有情节提要.

No code, just the storyboard.

我已经在导航栏中选中了喜欢大标题" 以激活大标题.现在,如果我运行该应用程序并在表格视图上向上/向下滚动,则导航栏保持不变-大-尺寸;它不会崩溃:

I've checked "Prefers large titles" for the navigation bar to activate large titles. Now, if I run the app and scroll up/down on the table view, the navigation bar stays the same - large - size; it doesn't collapse:

但是,我发现如果将第二个视图控制器的导航项设置为使用小导航栏(将大标题" 设置为值从不" ),然后,如果我打开该页面并向后浏览,则交互式折叠会神奇地开始在第一页上工作:

However, I've found that if I set the second view controller's navigation item to use the small navigation bar (by setting "Large Title" to the value "Never"), then if I open that page and navigate back, the interactive collapse magically starts working on the first page:

我在这里缺少什么吗?还是此功能无法正常工作?这是我正在使用的示例项目: https://github.com/tzahola/iOS-11-大型标题导航栏

Am I missing something here, or is this feature not working properly? Here's the sample project I'm using: https://github.com/tzahola/iOS-11-Large-Title-Navigation-Bar

顺便说一句,我使用的是正式发布的iOS 11,而不是Beta.

And by the way, I'm using the officially released iOS 11, not the betas.

2017-09-23更新:我已经向Apple发送了一个错误报告,并在openradar.me上打开了一张票:推荐答案

好消息!我刚刚发现,如果在情节提要板上将大标题" 设置为从不" ,然后通过代码进行设置,那么它将起作用:

Good news! I've just figured out that if I set "Large Titles" to "Never" on the storyboard, and then set it via code, then it works:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;
}

当导航项通过Interface Builder设置了largeTitleDisplayMode时,好像Apple忘记处理该情况.

Seems like Apple forgot to handle the case when the navigation item has its largeTitleDisplayMode set via the Interface Builder.

因此,在他们解决此问题之前,在情节提要板上将大标题" 保留为从不" ,并通过viewDidLoad中的代码进行设置.

So until they fix this issue, leave "Large Titles" as "Never" on storyboards, and set them via code in viewDidLoad.

您只需要对第一个视图控制器执行此操作.后续的视图控制器会尊重情节提要中的价值.

这篇关于iOS 11大标题导航栏未折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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