我想只在一个ViewController中使NavigationBar透明.但是,在单个ViewController中更改NavigationBar后,整个navigationController变得透明,并在几秒钟后崩溃.这是我的代码块:
override func viewWillAppear(animated: Bool) { self.navigationController!.navigationBar.setBackgroundImage(UIImage(),forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.translucent = true self.navigationController!.view.backgroundColor = UIColor.clearColor() } override func viewDidDisappear(animated: Bool) { self.navigationController!.navigationBar.setBackgroundImage(nil,forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = nil self.navigationController?.navigationBar.translucent = true }
它崩溃了
self.navigationController!.navigationBar.setBackgroundImage(nil,forBarMetrics: UIBarMetrics.Default)
解决方法
尝试给出代码,使导航栏在swift中透明: –
self.navigationController!.navigationBar.setBackgroundImage(UIImage(),forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.translucent = true self.navigationController!.view.backgroundColor = UIColor.clearColor() self.navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
希望这段代码能帮到你..谢谢