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

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

问题描述

没有代码,只有故事板.

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

但是,我发现如果我将第二个视图控制器的导航项设置为使用小导航栏(通过将 "Large Title" 设置为值 "Never"),然后如果我打开该页面并返回,交互式折叠神奇地开始在第一页上工作:

我在这里遗漏了什么,还是此功能无法正常工作?这是我正在使用的示例项目:https://github.com/tzahola/iOS-11-Large-Title-Navigation-Bar

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

2017-09-23 更新:我已经向 Apple 发送了错误报告,并在 openradar.me 上打开了一张票:http://www.openradar.me/radar?id=5017601935671296

解决方案

好消息!我刚刚发现,如果我在情节提要上将 "Large Titles" 设置为 "Never",然后通过代码进行设置,那么它可以工作:

- (void)viewDidLoad {[超级视图DidLoad];self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;}

当导航项通过 Interface Builder 设置其 largeTitleDisplayMode 时,Apple 似乎忘记处理这种情况.

因此,在他们解决此问题之前,请将 "Large Titles" 保留为故事板上的 "Never",并通过 viewDidLoad 中的代码设置它们.

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

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)

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.

Here's what I have:

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:

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

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

2017-09-23 Update: I've sent a bug report to Apple, and opened a ticket on openradar.me: http://www.openradar.me/radar?id=5017601935671296

解决方案

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;
}

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

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

You just need to do that to the first view controller. Subsequent view controllers honor the value in storyboard.

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

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