权当自己记录了, 不咋想好好写文章了
只有在iPhoneX上有这个问题, 以前没发现啊
导航的部分代码
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if self.viewControllers.count > 0 {
viewController.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
返回部分的代码
@IBAction func back(_ sender: Any) {
// 第一种有问题
self.navigationController?.popToRootViewController(animated: true)
// 第二种有问题
if let vcs = self.navigationController?.viewControllers {
for vc in vcs {
if vc.isKind(of: First2ViewController.self) {
self.navigationController?.popToViewController(vc, animated: true)
}
}
}
// 第三种可以
var vcs = self.navigationController?.viewControllers
vcs!.remove(at: vcs!.count-2)
self.navigationController?.viewControllers = vcs!
self.navigationController?.popViewController(animated: true)
}
原因:
在iPhoneX上直接返回到根视图的时候,正常是出栈, 但是去了栈低。
结果到最后是navigationConroller的viewControllers里有两个vc。
到底是不是iPhoneX的bug,我也不纠结了,问题搞定了。 但是这个有问题的返回是什么原理就有点好奇了, 自己不知道