繁体   English   中英

iOS 13 在标签栏子视图中 controller viewWillAppear 未被调用

[英]iOS 13 In Tab Bar child view controller viewWillAppear is not called

我有一个标签栏 controller,我在其中添加了五个视图控制器,如下所示:

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
}
}

问题是我的第一个 controller,即findWorkVC ,它的 viewWillAppear 被调用,但是当我点击任何其他视图 controller 时,他们的 viewWillAppear 没有被调用。

它在 iOS 13 设备上运行良好,但在 iOS 13 上,它不仅被调用,而且导航栏的高度也小于 iOS 12 的导航栏的标题,您可以在文本中看到导航栏的高度,

在此处输入图像描述

我创建了一个新项目并测试了所有内容,使用选项卡查看控制器,一切正常,但在我的项目中没有,所以我开始寻找我的项目中与新创建的项目不同的东西。

原来,这是根视图 controller。 我正在使用 animation 像这样设置根视图 controller

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
})

所以我只是简单地展示了视图 controller 和modalPresentationStyle =.fullScreen没有 animation 并且一切正常。

let controller = InfluencerMainTabBarController.instantiate(fromAppStoryboard: .Main)
controller.modalPresentationStyle = .fullScreen
DispatchQueue.main.async { UIApplication.shared.keyWindow?.rootViewController = controller }

现在我只需要寻找如何设置根视图 controller 和 animation。 :|

如果您的演示样式不是 Apple 的新默认设置(表格),那么只需将所有 ViewController(包括 NavigationController)的演示样式设置为 FullScreen。 这样,每个 VC 都会再次调用 viewWillAppear 方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM