gpt4 book ai didi

ios - 大标题到常规标题及其背面

转载 作者:行者123 更新时间:2023-11-30 11:16:19 25 4
gpt4 key购买 nike

我想要一个带有大标题的 View ,然后推送另一个带有常规标题的 View ,然后返回到带有大标题的上一个 View 。

我尝试在 viewWillAppear 的第一个 View 中设置 prefersLargeTitles = true 并在 的第二个 View 中设置 prefersLargeTitles = false viewWillAppear。这是可行的,但标题没有像从第二个 View 到第一个 View 时通常那样平滑过渡。

class FirstViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = true
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let secondViewController = secondViewController.storyboardInstance() {
self.navigationController?.pushViewController(secondViewController, animated: true)
}
}
}

class SecondViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = false
}

}

最佳答案

因此,您依赖于largeTitleDisplayMode的默认值,即.automatic,并且您使用prefersLargeTitles首先为true,然后为。这没有什么问题,但我确实认为 .automatic 有点令人困惑,因为它将采用任何先前的值,而不是仅在导航 Controller 的第一个 View Controller 上设置。

如果可以的话,我会这样做:

  • FirstVClargetitleDisplayMode = .alwaysprefersLargeTitle = true
  • SecondVC ,其中 largeTitleDisplayMode = .neverprefersLargeTitle = true (是的..它必须是 true..)

SecondVC 必须使用 prefersLargeTitle = true 因为从 Apple 文档中我们可以读到:

If the prefersLargeTitles property of the navigation bar is false, this property has no effect and the navigation item’s title is always displayed as a small title.

我写了一篇文章,围绕这个主题进行了更多的挖掘,其中我还解释了如何修复 .automatic https://www.morningswiftui.com/blog/fix-large-title-animation-on-ios13

关于ios - 大标题到常规标题及其背面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com