use*_*773 17 iphone uinavigationbar ios imessage ios10
iOS 10消息应用程序的导航栏在您按/弹出对话时(平滑过渡)增加/减少高度.
通常我会使用更高的自定义导航栏sizeThatFits:,但它会持续存在于导航控制器中的视图控制器的推送和弹出中.
如何为导航序列(例如消息应用程序)中的某些视图控制器设置更高的导航栏?谢谢!
非常有趣的问题。我花了一些时间在Messages应用程序中实现了类似的目的,这就是我所做的。
最后,我使用此技巧在推入/弹出期间动画化NavigationBar的高度,并以滑动手势弹出。
UIView.beginAnimations(nil, context: nil)
self.frame = navFrame
UIView.commitAnimations()
Run Code Online (Sandbox Code Playgroud)
在下面您可以看到我的实现:
extension UINavigationBar {
func applyHeight(_ height: CGFloat, animated: Bool = true) {
var navFrame = self.frame
navFrame.size.height = height
if animated {
UIView.beginAnimations(nil, context: nil)
self.frame = navFrame
UIView.commitAnimations()
} else {
self.frame = navFrame
}
}
}
class ViewControllerA: UIViewController {
override func loadView() {
super.loadView()
title = "A"
view.backgroundColor = .blue
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "NEXT", style: .plain, target: self, action: #selector(self.showController))
navigationController?.navigationBar.isTranslucent = false
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func showController() {
navigationController?.pushViewController(ViewControllerB(), animated: true)
}
}
class ViewControllerB: UIViewController {
override func loadView() {
super.loadView()
title = "B"
view.backgroundColor = .red
}
override func viewWillAppear(_ animated: Bool) {
navigationController?.navigationBar.applyHeight(100)
super.viewWillAppear(animated)
}
override func willMove(toParentViewController parent: UIViewController?) {
if parent == nil { // here you know that back button was tapped
navigationController?.navigationBar.applyHeight(44)
}
super.willMove(toParentViewController: parent)
}
}
Run Code Online (Sandbox Code Playgroud)
滑动弹出时可以看到跳转标题,但就我个人而言,我认为这是一个小问题:)
希望它能对您有所帮助,也许有人可以改善此实现。当然,我仍将尝试弄清楚如何使其变得更好:)这是一个github存储库。请使用navigation_bar_height分支。
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |