ios – 如何才能在一个视图控制器中使UINavigationController透明?

前端之家收集整理的这篇文章主要介绍了ios – 如何才能在一个视图控制器中使UINavigationController透明?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想只在一个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()

希望这段代码能帮到你..谢谢

猜你在找的iOS相关文章