我有一个应用程序,需要在第一个ViewController的清晰navigationBar,并在第二个白色navigationBar。
问题是,当我在控制器之间移动时(通过UIBarButton),这个可怕的白色条纹仍然存在。怎么了?
//for first ViewController to hide navigationBar, second is the same, but "true" and .white
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = .clear
navigationController?.navigationBar.setValue(false, forKey: "hidesShadow")At first start it works fine, but when you return with button:
发布于 2020-04-13 03:43:18
问题是,您的两个控制器都嵌入到具有自己的单个导航栏的单个导航控制器中。
因此,当您在第二个控制器上更改导航栏的颜色和样式,然后返回到第一个控制器时,这些更改会保留下来,因此您会看到白条。
我建议您隐藏第一个控制器的工具栏,并在第二个控制器上显示它。或者每次在viewWillAppear方法中改变它的样式(颜色,背景图像)。
发布于 2020-04-13 11:56:52
不要修改first View控制器导航栏。在AppDelegate中添加要在第二个视图中包含的修改和更改第一个视图控制器在viewWillAppear中隐藏导航栏,然后在viewWillDisappear.中再次显示
在第一个视图控制器中
override func viewWillAppear(_ animated: Bool) {
navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
navigationController?.setNavigationBarHidden(false, animated: true)
}https://stackoverflow.com/questions/61176955
复制相似问题