简体   繁体   English

IOS 大标题 - 在启动新活动时捕捉

[英]IOS Large Title - Snapping upon launching new activity

I have a problem within my app where a LargeTitle is set on View1, however when I launch View2 the title snaps back to small.我的应用程序中有一个问题,即在 View1 上设置了 LargeTitle,但是当我启动 View2 时,标题又变小了。 As a result when the back button is pressed on View2, View1 launches with the LargeTitle snapping from small to large.因此,当在 View2 上按下后退按钮时,View1 启动时 LargeTitle 从小到大对齐。

The code I have used to create LargeTitle is 'navigationItem.largeTitleDisplayMode =.always' which is within the ViewWillAppear.我用来创建 LargeTitle 的代码是 ViewWillAppear 中的“navigationItem.largeTitleDisplayMode =.always”。

View1 -视图1 -

'override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) '覆盖函数viewWillAppear(_动画:布尔){ 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]
            
        }

' '

View2 -视图2 -

'override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) '覆盖函数viewWillAppear(_动画:布尔){ 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)'

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

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

    self.navigationController?.navigationBar.isTranslucent = true;

}'

This is the code I have used associated with title text for both View's.这是我使用的与两个视图的标题文本相关联的代码。 The storyboard is nested in a NavigationController, so this may have something to do with it. storyboard 嵌套在 NavigationController 中,所以这可能与它有关。

NOTE - I have not set LargeTitle via Storyboard, however when doing so this does not fix the issue.注意 - 我没有通过 Storyboard 设置 LargeTitle,但是这样做并不能解决问题。

Here is a video snippet of the problem.这是该问题的视频片段。 :

Snapping LargeTitle:-捕捉大标题:-

在此处输入图像描述

I think the issue is that you need to restore navigationItem.largeTitleDisplayMode =.always' in the second view when it's about to disappear我认为问题是您需要在第二个视图中恢复 navigationItem.largeTitleDisplayMode =.always' 当它即将消失时

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

       navigationItem.largeTitleDisplayMode = .always'
    }

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

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