首页 > 解决方案 > 推送后导航栏不会出现

问题描述

我有一个登录和主页 Viewcontrollers,从 loginVC 移动到 homeVC 后,导航栏被隐藏,我尝试了一些东西但没有任何效果。这就是我从登录到主页的方式:

func handleLogin() {
    guard let email = self.mView.emailTxtField.text else { return }
    guard let pass = self.mView.passTxtField.text else { return }
    Service.shared.loginUser(email, pass) { (answer) in
        if answer == true {

            UserDefaults.standard.set(Auth.auth().currentUser?.uid, forKey:     USER_UID_KEY)
            let vc = HomeVC(collectionViewLayout: UICollectionViewFlowLayout())

            let transition = CATransition()
            transition.duration = 0.5
            transition.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
            transition.type = .push
            transition.subtype = .fromTop
            self.navigationController?.view.layer.add(transition, forKey: kCATransition)
            self.navigationController?.pushViewController(vc, animated: false)

        }else {
            //TODO: SHOW ERROR
            print("CAN'T LOGIN ....")
        }
    }
}

标签: swift

解决方案


Login VC出现时必须隐藏导航栏,消失时隐藏。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    navigationController?.setNavigationBarHidden(false, animated: animated)
}

推荐阅读