当我从具有不同阴影自定义的大标题导航栏的视图转换到具有常规高度导航栏的另一个视图时,会发生奇怪的事情。你可以看到这个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
}
在界面构建器中也没有黑色背景的视图。我不确定为什么会这样。
答案 0 :(得分:1)
的Instad
navigationController?.navigationBar.isTranslucent = false
使用
navigationController?.navigationBar.isTranslucent = true