【问题标题】:IOS Large Title - Snapping upon launching new activityIOS 大标题 - 在启动新活动时捕捉
【发布时间】:2021-03-22 11:40:02
【问题描述】:

我的应用程序中有一个问题,即在 View1 上设置了 LargeTitle,但是当我启动 View2 时,标题又变小了。因此,当在 View2 上按下后退按钮时,View1 启动时 LargeTitle 从小到大对齐。

我用来创建 LargeTitle 的代码是 ViewWillAppear 中的 'navigationItem.largeTitleDisplayMode = .always'。

视图1-

'override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(动画)

        navigationItem.largeTitleDisplayMode = .always

if #available(iOS 12.0, *) {
           
            self.navigationController?.navigationBar.barTintColor = UIColor(named: "#222222")
               
            self.navigationController?.navigationBar.isTranslucent = true;

            self.navigationController?.navigationBar.tintColor = UIColor.white
                
            navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
            
        }

'

视图2-

'override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(动画)

    self.navigationController?.setToolbarHidden(true, animated: false)
    
    navigationController?.navigationBar.prefersLargeTitles = false

    if #available(iOS 13.0, *) {
        UIApplication.shared.statusBarStyle = .darkContent
    } 
    
    if #available(iOS 12.0, *) {
        self.navigationController?.navigationBar.barTintColor = UIColor.white
            self.navigationController?.navigationBar.isTranslucent = false;
            self.navigationController?.navigationBar.tintColor = UIColor.black
            navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]

    }
    
    self.navigationItem.titleView = setTitle(title: name, titleColor: UIColor.black, titleSize: 14, subtitle: category, subtitleColor: UIColor.gray, subtitleSize: 12, view: self.view)'

' 覆盖 func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(动画)

    navigationController?.navigationBar.prefersLargeTitles = true
    
    navigationController?.navigationItem.largeTitleDisplayMode = .always
    
    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

    self.navigationController?.navigationBar.isTranslucent = true;

}'

这是我使用的与两个视图的标题文本相关联的代码。故事板嵌套在 NavigationController 中,所以这可能与它有关。

注意 - 我没有通过 Storyboard 设置 LargeTitle,但是这样做并不能解决问题。

这是该问题的视频 sn-p。 :

捕捉大标题:-

【问题讨论】:

  • 您需要在第二个 viewController 上使用大标题。你能分享一些代码让我们看看发生了什么吗?
  • @MobileMon 我现在已经用相关代码更新了问题,提前感谢您的帮助。 !!
  • 您需要发布重现问题所需的所有代码。
  • @GJNilsen 道歉。我现在更新了 NavBar 的详细代码。
  • @GeorgeParkinson:您需要发布重现问题所需的所有内容。将其粘贴到 Xcode 中没有任何作用。请阅读如何发布问题:stackoverflow.com/help/minimal-reproducible-example

标签: ios swift title preferslargetitles


【解决方案1】:

我认为问题是您需要在第二个视图中恢复 navigationItem.largeTitleDisplayMode = .always' 当它即将消失时

override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

       navigationItem.largeTitleDisplayMode = .always'
    }

【讨论】:

  • 感谢您的回复。对此进行测试后,不幸的是,这并不能解决问题。
猜你喜欢
  • 2022-01-22
  • 2023-02-02
  • 1970-01-01
  • 1970-01-01
  • 2021-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
相关资源
最近更新 更多