在 swift 4、iOS 11 中的 UICollectionView 中添加导航栏 [英] Add Navigation Bar in UICollectionView in swift 4, iOS 11
问题描述
升级 iOS 11 和 swift 4(Xcode 9) 后,我遇到了很多 UI 问题.:(
最无法解决的问题是导航问题.
我将导航栏放在 UICollectionView 控制器中.
导航栏高度未正确显示,但是我编写了代码.
After upgrading the iOS 11 and swift 4(Xcode 9), I got lots of UI problem. :(
The most unsolvable problem is Navigation Problem.
I put the Navigation Bar in UICollectionView Controller.
Navigation bar height does not show properly and however I write the code.
我将导航栏高度设置为100".我在 ViewDidLoad() 中编写此代码.
I set navigation bar height "100". I write this code in ViewDidLoad().
if #available(iOS 11.0, *) {
print("IOS 11 Screen")
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
]
navigationItem.largeTitleDisplayMode = .never
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
} else {
print("lower than IOS 11 Screen")
// Fallback on earlier versions
}
collectionview?.frame = CGRect(x: 0, y: 10, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.height + 20)) <br>
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
override func viewWillAppear(_ animated: Bool) {
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
但是,我尝试使用此代码.没有什么对我有用.
However, I tried with this code. Nothing works for me.
我还尝试使用源代码视图打开故事板并编辑导航栏的高度.但是,它也不起作用.
任何人都可以帮助我吗?从前两天开始,我一直在尝试解决这个问题.
I also tried to open the storyboard with source code view and I edit the height of Navigation bar. But, it also does not work.
Can anyone help me please? I have been trying to solve this problem since last two days.
推荐答案
请查看:
override func viewDidLoad() {
if #available(iOS 11.0, *) {
print("IOS 11 Screen")
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
]
self.navigationController?.navigationBar.prefersLargeTitles = true // added this line
navigationItem.largeTitleDisplayMode = .never
} else {
print("lower than IOS 11 Screen")
// Fallback on earlier versions
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
这篇关于在 swift 4、iOS 11 中的 UICollectionView 中添加导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!