【发布时间】:2017-01-18 17:32:06
【问题描述】:
我正在尝试了解如何更改导航栏的高度。每当我在我的应用程序中插入一个时,它都比 Apple 的股票应用程序(例如消息和设置)中使用的所有导航栏都要短。我希望它达到那个高度,因为当我尝试添加一个栏按钮时,它与状态栏冲突。我还读到,作为开发人员,您不应该更改导航栏的高度,所以我有点困惑。最后,我查看了这个 Stack Overflow 页面:How can I change height of Navigation Bar Swift 3。 我尝试实现代码...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let height: CGFloat = 50 //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)
}
...但是当我这样做时我的应用程序崩溃了。 我正在使用 Xcode 8.2 beta 和 Swift 3。
【问题讨论】:
-
显示导致崩溃的代码。
-
@toddg override fund viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let height: CGFloat = 50 let bounds = self.navigationController!.navigationBar.bounds self.navigationController?.navigationBar. frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) }
-
编辑您的问题并将代码放在那里。
-
我现在这样做了@toddg
-
它可能与
self.navigationController!.navigationBar.bounds在线崩溃,对吧?如果是这种情况,则可能由于不存在navigationController而发生崩溃。
标签: ios swift xcode uinavigationbar