从自定义大标题导航栏过渡到常规导航栏时出现黑框
Posted
技术标签:
【中文标题】从自定义大标题导航栏过渡到常规导航栏时出现黑框【英文标题】:Black box when transitioning from custom large title nav bar to regular nav bar 【发布时间】:2017-12-04 15:19:29 【问题描述】:当我从一个带有大标题导航栏的视图过渡到另一个具有常规高度导航栏的视图时,会发生一件奇怪的事情。你可以在这个 gif 中看到黑框
这是同时存在于主视图和详细视图中的相关代码
主视图:
func setupNavBar()
// Set the nav bar to have large titles. This is on a per instance basis
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = UIColor.white
navigationController?.navigationBar.tintColor = UIColor.black
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.layer.shadowColor = UIColor(red:0.87, green:0.87, blue:0.87, alpha: 0.3).cgColor
navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 3.0)
navigationController?.navigationBar.layer.shadowRadius = 6.0
navigationController?.navigationBar.layer.shadowOpacity = 1.0
navigationController?.navigationBar.layer.masksToBounds = false
详细视图:
func setupNavBar()
self.title = colorPalette?.title
navigationController?.navigationBar.prefersLargeTitles = false
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = UIColor.white
navigationController?.navigationBar.tintColor = UIColor.black
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.layer.shadowColor = UIColor(red:0.87, green:0.87, blue:0.87, alpha: 0.3).cgColor
navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 3.0)
navigationController?.navigationBar.layer.shadowRadius = 6.0
navigationController?.navigationBar.layer.shadowOpacity = 1.0
navigationController?.navigationBar.layer.masksToBounds = false
界面生成器中也没有黑色背景的视图。我不确定为什么会这样。
【问题讨论】:
【参考方案1】:代替
navigationController?.navigationBar.isTranslucent = false
使用
navigationController?.navigationBar.isTranslucent = true
【讨论】:
【参考方案2】:在故事板上勾选✓ Extended Edges Under Opaque Bars
,或设置
extendedLayoutIncludesOpaqueBars = true
或者将navigationBar的半透明设置为true。
navigationController?.navigationBar.isTranslucent = true
【讨论】:
以上是关于从自定义大标题导航栏过渡到常规导航栏时出现黑框的主要内容,如果未能解决你的问题,请参考以下文章