swift返回首页底部留白
进入二级界面,返回到
BaseTabBarController
的任意一级界面,在部分机型会出现一下情况出现的代码
weakSelf.navigationController?.popToRootViewController(animated: false)
guard let tabBarC = UIApplication.shared.keyWindow?.rootViewController as? BaseTabBarController else {
return
}
tabBarC.tabBar.isHidden = false
if tabBarC.selectedIndex != UITabBarController.SelectType.resume.rawValue {
tabBarC.selectedIndex = UITabBarController.SelectType.resume.rawValue
}
解决
BaseTabBarController.back(.resume)
分析
可能和
viewController.hidesBottomBarWhenPushed = true
使用不规范;还有在调用
popToRootViewController
后立即调用了 tabBarC.tabBar.isHidden = false
的有关extension BaseTabBarController{
/// 回到首页
static func back(_ type: UITabBarController.SelectType = .recruit) {
/// 直接 backroot 在12上view的高度会少49、故用此方式替换;
let nav = GetCurrentVC()?.navigationController
let vcs = nav?.viewControllers ?? []
if vcs.count > 1 {
nav?.setViewControllers([vcs[0]], animated: false)
}
guard let tabBarCrl = UIApplication.shared.keyWindow?.rootViewController as? UITabBarController else { return }
tabBarCrl.selectedIndex = type.rawValue
}
}