在UICollectionView中添加导航栏在iOS 4中,iOS 11
升级iOS 11和Swift 4(Xcode 9)后,我遇到了很多UI问题。 :(
最无法解决的问题是导航问题。
我把导航栏UICollectionView控制器。
导航栏高度不正确显示和但是我写的代码。
在UICollectionView中添加导航栏在iOS 4中,iOS 11
我设置导航栏的高度“ 100" 。我写这篇文章的代码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)
}
不过,我试着用这个代码。没有为我工作。
我还试图打开源代码视图故事板,我编辑导航栏的高度。但是,这也行不通。
任何人都可以帮助我吗?自过去两天以来,我一直试图解决这个问题。
请检查:
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)
}
我现在可以解决这个问题。但我有另一个问题https://stackoverflow.com/questions/46376475/uinavigationbar-does-not-overlap-to-uicollectionview-in-swift-4你能帮我兄弟吗? –
你的解决方案是什么? @MayPhyu – antonio081014
@ antonio081014,我参考这个链接https://stackoverflow.com/questions/31940352/how-to-increase-the-height-of-navigation-bar-in-xcode。我增加空间来增加导航栏bro –
我不认为你可以调整导航栏的高度。相反,您可以创建一个自定义导航栏,同时覆盖系统给出的导航栏。 – antonio081014