按下和弹出视图控制器时,导航栏保持不变,过渡时会产生怪异的白色效果

时间:2018-11-02 08:08:47

标签: ios swift xcode uiviewcontroller uinavigationcontroller

我有一个navigationController,它正被用来在我的ViewControllers之间移动。

我正常设置了它,并且我为每个View Controller使用Xib。

extension UINavigationController{

    func setup(){

        if #available(iOS 11.0, *) {
            self.navigationController?.navigationBar.prefersLargeTitles = true
            self.navigationController?.navigationItem.largeTitleDisplayMode = .always
        } else {
            // Fallback on earlier versions
        }

        self.navigationBar.isTranslucent = true
        self.view.backgroundColor = UIColor.red


        self.navigationBar.clipsToBounds = true
        self.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationBar.shadowImage = UIImage()

        self.navigationBar.tintColor = UIColor(hexString: "#373839")

    }
}

这是我用于UINavigation控制器的扩展名。

在按下的视图(第二视图)中,我需要具有不同的向左和向右按钮,因此我隐藏了后退的导航,并具有用于设置按钮的自定义代码。

func setUI(){


        self.navigationController?.navigationItem.hidesBackButton = true
        self.navigationController?.navigationBar.clipsToBounds = true
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationController?.navigationBar.shadowImage = UIImage()

        let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))

        let hostStr = host
        print(hostStr)
        let searchImage    = UIImage(named: "Search_Icon3")!
        let notificationImage  = UIImage(named: "Notification_Icon3")!
        let profileImage  = UIImage(named: "test_Profile")!
        let backImage  = UIImage(named: "Back_Icon3")!

        let searchButton   = UIBarButtonItem(image: searchImage,  style: .plain, target: self, action: #selector(searchViewButtonPressed(_:)))
        let notificationButton   = UIBarButtonItem(image: notificationImage,  style: .plain, target: self, action: #selector(notificationViewButtonPressed(_:)))
        let profileButton = UIBarButtonItem(image: profileImage,  style: .plain, target: self, action: #selector(profileViewButtonPressed(_:)))
        let backButton   = UIBarButtonItem(image: backImage,  style: .plain, target: self, action: #selector(backButtonPressed(_:)))



        self.navigationItem.rightBarButtonItems = [profileButton,notificationButton,searchButton]
        self.navigationController?.navigationBar.tintColor = UIColor(hexString: "#373839")
        self.navigationItem.leftBarButtonItem = backButton

        self.setValues()
    } 

但是当我将ViewController从1推到2并将Pop从2推到1时,我会在过渡之间得到这种奇怪的导航栏呈现效果


0 个答案:

没有答案