swift - 推送后导航栏不会出现
问题描述
我有一个登录和主页 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 ....")
}
}
}
解决方案
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)
}
推荐阅读
- keyboard - SwiftUI 中出现键盘时 OnAppear 意外调用
- node.js - 如何动态导入和使用修改后的 npm 库包
- json - Web API POST,获取对象和 JSON 纯文本
- docker - Hazelcast 无法连接到 Hazelcast-mancenter
- python - 如何从另一个类的函数访问一个类的函数输出
- c++ - 在 C++ 中使用迭代器时出现缓冲区溢出错误
- pentaho - 如何在元数据注入中使用 Pentaho Denormalizer Step
- python - Python:熊猫列中的部分字符串匹配并从熊猫数据框中的其他列中检索值
- java - 并行执行具有返回类型和输入参数的方法
- android - 处理一个获取RNCWebView的android项目没有找到错误