Swift 切换选项卡时,大标题导航栏重叠

Swift 切换选项卡时,大标题导航栏重叠,swift,scrollview,tabbar,Swift,Scrollview,Tabbar,在选项卡栏控制器中使用导航控制器,切换选项卡时会出现较大的标题问题 斯威夫特美术馆 if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) let tabBarController = UITabBarController() tabBarController.viewControllers = [UINavi

在选项卡栏控制器中使用导航控制器,切换选项卡时会出现较大的标题问题

斯威夫特美术馆

if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)

        let tabBarController = UITabBarController()
        tabBarController.viewControllers = [UINavigationController(rootViewController: ViewController()), UIViewController()]

        window.rootViewController = tabBarController
        self.window = window
        window.makeKeyAndVisible()
    }
ViewController.swift

 self.view.backgroundColor = .systemBackground

    self.title = "Main"
    self.navigationController?.navigationBar.prefersLargeTitles = true
    self.navigationItem.largeTitleDisplayMode = .always

    scrollView = UIScrollView(frame: self.view.bounds)
    self.view.addSubview(scrollView)

    let contentView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 1400))
    contentView.backgroundColor = .gray
    self.scrollView.addSubview(contentView)

    scrollView.contentSize.height = 1700
复制步骤:

  • 向下滚动,直到大标题折叠为小标题
  • 切换到第二个选项卡
  • 切换回第一个选项卡
  • 结果:滚动视图仍向下滚动,但大标题现在与内容重叠。当滚动一点时,它会回到小标题
当它是表或集合视图而不是滚动视图时,不会发生这种情况


这是从iOS 13开始的。我是否错过了行为上的一些改变,或者这是一个bug?有人知道解决方法吗?

我也有同样的问题,你知道如何解决吗?是的。基本上,您必须设置contentSize的高度和宽度。如果不设置宽度,它将无法工作。这是一个愚蠢的错误。