我有一个标签栏控制器,并在其中添加了五个视图控制器,如下所示:
class InfluencerMainTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let findWorkVC = UINavigationController.init(rootViewController: InfluencerFindWorkVC.instantiate(fromAppStoryboard: .Influencer))
findWorkVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_home"), tag: 0)
let inboxVC = UINavigationController.init(rootViewController: InfluencerInboxVC.instantiate(fromAppStoryboard: .Inbox))
inboxVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_inbox"), tag: 1)
let workDiaryVC = UINavigationController.init(rootViewController: InfluencerWorkDiaryVC.instantiate(fromAppStoryboard: .Influencer))
workDiaryVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_work"), tag: 2)
let notificationsVC = InfluencerNotificationsVC.instantiate(fromAppStoryboard: .Influencer)
notificationsVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_notification"), tag: 3)
let accountVC = InfluencerProfileVC.instantiate(fromAppStoryboard: .Influencer)
accountVC.tabBarItem = UITabBarItem(title: nil, image: #imageLiteral(resourceName: "ic_profile"), tag: 4)
let tabBarList = [findWorkVC, inboxVC, workDiaryVC, notificationsVC, accountVC]
viewControllers = tabBarList
self.tabBar.tintColor = UIColor.appPurpleColor
self.tabBar.barTintColor = UIColor.white
}
}
问题是我的第一个控制器,它是 findWorkVC ,它的viewWillAppear被调用,但是当我单击任何其他视图控制器时,它们的viewWillAppear没有被调用。
它在iOS 13之前的设备上运行良好,但是在iOS 13上它不仅被调用,而且导航栏的高度小于iOS 12的导航栏高度,您可以看到导航栏中的标题与状态栏重叠文字。
答案 0 :(得分:1)
我创建了一个新项目,并测试了所有内容,使用选项卡查看控制器,所有功能均在其中运行,但在我的项目中不起作用,所以我开始寻找与新创建项目不同的项目。
原来,它是根视图控制器。我正在用动画设置像这样的根视图控制器
let controller = InfluencerMainTabBarController.instantiate(fromAppStoryboard: .Main)
UIView.transition(from: self.view, to: controller.view, duration: 0.6, options: [.transitionFlipFromTop], completion: { completed in
UIApplication.shared.keyWindow?.rootViewController = controller
})
因此,我只是向视图控制器提供了modalPresentationStyle = .fullScreen
而没有动画,并且一切正常。
let controller = InfluencerMainTabBarController.instantiate(fromAppStoryboard: .Main)
controller.modalPresentationStyle = .fullScreen
DispatchQueue.main.async { UIApplication.shared.keyWindow?.rootViewController = controller }
现在我只需要寻找如何用动画设置根视图控制器。 :|
答案 1 :(得分:0)
如果您的演示文稿样式不是Apple(表)的新默认样式,则只需将所有ViewController(包括NavigationController)的演示文稿样式设置为FullScreen。这样,将为每个VC再次调用viewWillAppear方法。