I have a UITableView and a Detail View embedded in a UINavigationController as so: I would like to turn on large titles for "My Notes" but I'd like to turn it off for the detail view. Something like how the default Mail app works on iPhone. How would I change the navigation bar's prefersLargeTitle
property during that segue?
我在UINavigationController中嵌入了一个UITableView和一个Detail视图:我想为“我的笔记”打开大标题,但我想为Detail视图关闭它。比如iPhone上的默认邮件应用。在那个segue中,我如何更改导航条的prefersLargeTitle属性?
3 个解决方案
#1
2
Any one of both of following, will solve your problem:
以下任何一种都可以解决你的问题:
-
set prefersLargeTitles to false for your navigationBar
为您的导航栏设置preferslargetitle为false
self.navigationController?.navigationBar.prefersLargeTitles = false
-
set largeTitleDisplayMode to never for navigationItem (note: prefersLargeTitles must be false otherwise this won't work)
将largeTitleDisplayMode设置为决不为navigationItem(注意:preferslargetitle必须为false,否则将不起作用)
self.navigationController?.navigationItem.largeTitleDisplayMode = .never
Note: if prefersLargeTitles
is true, then largeTitleDisplayMode = .never won't work. Small title display for navigation bar is dependent on prefersLargeTitles
注意:如果preferslargetitle是true,那么largeTitleDisplayMode = .永远都不会工作。导航栏的小标题显示依赖于首选大标题
This will enable large title mode if it's value is true
如果值为true,则启用大标题模式
self.navigationController?.navigationBar.prefersLargeTitles = true
#2
0
if #available(iOS 11.0, *) {
self.navigationItem.largeTitleDisplayMode = UINavigationItem.LargeTitleDisplayMode.never
} else {
// Fallback on earlier versions
}
#3
0
I had the same issue just now.
我刚才也有同样的问题。
My use case:
我的用例:
MasterVC: basic navigation bar without largeTitle
MasterVC:没有largeTitle的基本导航栏。
DetailVC: largeTitle enabled
能够实现:largeTitle启用
--> When going back to the MasterVC from the DetailVC I was seeing a weird animation which showed a largeTitle on the Master for a sec before going back to the basic non largeTitle layout. It looked like a glitch.
——>当我从DetailVC回到MasterVC时,我看到一个奇怪的动画,它在Master上显示了一个大标题一段时间,然后回到基本的非大标题布局。它看起来像个小故障。
I fixed it by following this approach:
我通过以下方法解决了这个问题:
In MasterVC - viewDidLoad
MasterVC - viewDidLoad
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .never
navigationController?.navigationBar.prefersLargeTitles = false
}
In DetailVC - viewDidLoad
在能够实现- viewDidLoad
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .always
navigationController?.navigationBar.prefersLargeTitles = true
}
I hope that can help others.
我希望能帮助别人。
#1
2
Any one of both of following, will solve your problem:
以下任何一种都可以解决你的问题:
-
set prefersLargeTitles to false for your navigationBar
为您的导航栏设置preferslargetitle为false
self.navigationController?.navigationBar.prefersLargeTitles = false
-
set largeTitleDisplayMode to never for navigationItem (note: prefersLargeTitles must be false otherwise this won't work)
将largeTitleDisplayMode设置为决不为navigationItem(注意:preferslargetitle必须为false,否则将不起作用)
self.navigationController?.navigationItem.largeTitleDisplayMode = .never
Note: if prefersLargeTitles
is true, then largeTitleDisplayMode = .never won't work. Small title display for navigation bar is dependent on prefersLargeTitles
注意:如果preferslargetitle是true,那么largeTitleDisplayMode = .永远都不会工作。导航栏的小标题显示依赖于首选大标题
This will enable large title mode if it's value is true
如果值为true,则启用大标题模式
self.navigationController?.navigationBar.prefersLargeTitles = true
#2
0
if #available(iOS 11.0, *) {
self.navigationItem.largeTitleDisplayMode = UINavigationItem.LargeTitleDisplayMode.never
} else {
// Fallback on earlier versions
}
#3
0
I had the same issue just now.
我刚才也有同样的问题。
My use case:
我的用例:
MasterVC: basic navigation bar without largeTitle
MasterVC:没有largeTitle的基本导航栏。
DetailVC: largeTitle enabled
能够实现:largeTitle启用
--> When going back to the MasterVC from the DetailVC I was seeing a weird animation which showed a largeTitle on the Master for a sec before going back to the basic non largeTitle layout. It looked like a glitch.
——>当我从DetailVC回到MasterVC时,我看到一个奇怪的动画,它在Master上显示了一个大标题一段时间,然后回到基本的非大标题布局。它看起来像个小故障。
I fixed it by following this approach:
我通过以下方法解决了这个问题:
In MasterVC - viewDidLoad
MasterVC - viewDidLoad
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .never
navigationController?.navigationBar.prefersLargeTitles = false
}
In DetailVC - viewDidLoad
在能够实现- viewDidLoad
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .always
navigationController?.navigationBar.prefersLargeTitles = true
}
I hope that can help others.
我希望能帮助别人。