<bdo id='GeLVf'></bdo><ul id='GeLVf'></ul>

        <small id='GeLVf'></small><noframes id='GeLVf'>

        <tfoot id='GeLVf'></tfoot>

        <legend id='GeLVf'><style id='GeLVf'><dir id='GeLVf'><q id='GeLVf'></q></dir></style></legend>
      1. <i id='GeLVf'><tr id='GeLVf'><dt id='GeLVf'><q id='GeLVf'><span id='GeLVf'><b id='GeLVf'><form id='GeLVf'><ins id='GeLVf'></ins><ul id='GeLVf'></ul><sub id='GeLVf'></sub></form><legend id='GeLVf'></legend><bdo id='GeLVf'><pre id='GeLVf'><center id='GeLVf'></center></pre></bdo></b><th id='GeLVf'></th></span></q></dt></tr></i><div id='GeLVf'><tfoot id='GeLVf'></tfoot><dl id='GeLVf'><fieldset id='GeLVf'></fieldset></dl></div>

        如何防止大标题折叠

        时间:2023-06-12
          <bdo id='nIYf4'></bdo><ul id='nIYf4'></ul>
        • <i id='nIYf4'><tr id='nIYf4'><dt id='nIYf4'><q id='nIYf4'><span id='nIYf4'><b id='nIYf4'><form id='nIYf4'><ins id='nIYf4'></ins><ul id='nIYf4'></ul><sub id='nIYf4'></sub></form><legend id='nIYf4'></legend><bdo id='nIYf4'><pre id='nIYf4'><center id='nIYf4'></center></pre></bdo></b><th id='nIYf4'></th></span></q></dt></tr></i><div id='nIYf4'><tfoot id='nIYf4'></tfoot><dl id='nIYf4'><fieldset id='nIYf4'></fieldset></dl></div>

            <legend id='nIYf4'><style id='nIYf4'><dir id='nIYf4'><q id='nIYf4'></q></dir></style></legend>
          1. <tfoot id='nIYf4'></tfoot>
              <tbody id='nIYf4'></tbody>

              • <small id='nIYf4'></small><noframes id='nIYf4'>

                • 本文介绍了如何防止大标题折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  问题很简单,如何防止大标题导航栏在滚动视图向下滚动时崩溃?

                  The question is simple, how can I prevent a Large Title Navigation Bar from collapse when a scrollview scrolls down?

                  我的导航必须始终有一个大导航栏...所以当滚动视图滚动时,导航栏不应该折叠起来,它应该保持相同的大小,我该怎么做?

                  My navigation must have a large navigation bar at all times... so when a scrollview scroll, the navigation bar shouldn't collapse up, it should stay the same size, how can I do that?

                  这就是我设置 largeTitle 首选项的方式

                  This is how I set the largeTitle preferences

                  override func viewWillAppear(_ animated: Bool) {
                      super.viewWillAppear(animated)
                      self.navigationItem.hidesBackButton = true
                      presenter.expandForSimulatorLayoutIfNeeded()
                  
                  }
                  
                  
                  func expandForSimulatorLayoutIfNeeded(){
                              if !isExpanded{
                          topMenu = TopMenu(frame: expandedNavigationFrame, interactor: interactor)
                          oldNavigationBarFrame = navigationBar.frame
                          self.navigationBar.addSubview(topMenu)
                      }
                  
                      if #available(iOS 11.0, *) {
                          self.navigationBar.prefersLargeTitles = true
                      } else {
                          self.navigationBar.frame = expandedNavigationFrame
                      }
                  
                      let topConstraint = NSLayoutConstraint(item: topMenu, attribute: .top, relatedBy: .equal, toItem: navigationBar, attribute: .top, multiplier: 1, constant: 0)
                      let leadingConstraint = NSLayoutConstraint(item: topMenu, attribute: .leading, relatedBy: .equal, toItem: navigationBar, attribute: .leading, multiplier: 1, constant: 0)
                      let widthConstraint = NSLayoutConstraint(item: topMenu, attribute: .width, relatedBy: .equal, toItem: self.navigationBar, attribute: .width, multiplier: 1, constant: 0)
                      let bottomConstraint = NSLayoutConstraint(item: topMenu, attribute: .bottom, relatedBy: .equal, toItem: navigationBar, attribute: .bottom, multiplier: 1, constant: 0)
                      topMenu.translatesAutoresizingMaskIntoConstraints = false
                      NSLayoutConstraint.activate([leadingConstraint, widthConstraint, topConstraint, bottomConstraint])
                  
                  }
                  

                  推荐答案

                  我想出的解决方法是添加一个不是 CollectionView/TableView 的占位符视图作为 中的第一个视图ViewController 的 基本视图.这第一个视图将附加到 safeArea 的顶部,高度可以为零.

                  A workaround i figured out is to add a placeholder view that is not CollectionView/TableView as the very first view in ViewController's base view. This first view will be attached to the top of the safeArea, height can be zero.

                  使用 Storyboard/Xib:

                  查看下面的屏幕截图,了解带有约束的视图

                  See the below screenshot for this view with constraints

                  接下来添加另一个 UIView 作为 TableView/CollectionView 的容器视图.此容器的顶部将附加到占位符视图的底部.有关容器视图和 TableView/CollectionView 的约束,请参见下面的屏幕截图.

                  Next add another UIView to serve as a container view for your TableView/CollectionView. This container's top will be attached to bottom of the placeholder view. See the below screenshot for constraints of container view and TableView/CollectionView.

                  这里的关键是视图层次结构中的第一个视图,因为 导航栏 将检查它以设置折叠效果.一旦它没有找到它作为 CollectionView/TableView,它就不会在滚动时折叠.

                  The key here is the first view in the view hierarchy as the navigation bar will check that to set the collapsing effect. Once it does not find it as a CollectionView/TableView, it will not collapse on scrolling.

                  以编程方式:

                  如果您以编程方式设置视图,那么您只需要在顶部添加一个占位符视图.

                  If you are setting up view's programmatically then you just need to add a placeholder view at the top.

                  例如,

                  self.view.addSubview(UIView(frame: .zero))
                  self.view.addSubview(tableView) // or collectionView
                  

                  这篇关于如何防止大标题折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用委托将数据传回导航堆栈 下一篇:UINavigationController 横向模式下的导航堆栈问题

                  相关文章

                  <small id='ZcM5G'></small><noframes id='ZcM5G'>

                • <legend id='ZcM5G'><style id='ZcM5G'><dir id='ZcM5G'><q id='ZcM5G'></q></dir></style></legend>
                  <i id='ZcM5G'><tr id='ZcM5G'><dt id='ZcM5G'><q id='ZcM5G'><span id='ZcM5G'><b id='ZcM5G'><form id='ZcM5G'><ins id='ZcM5G'></ins><ul id='ZcM5G'></ul><sub id='ZcM5G'></sub></form><legend id='ZcM5G'></legend><bdo id='ZcM5G'><pre id='ZcM5G'><center id='ZcM5G'></center></pre></bdo></b><th id='ZcM5G'></th></span></q></dt></tr></i><div id='ZcM5G'><tfoot id='ZcM5G'></tfoot><dl id='ZcM5G'><fieldset id='ZcM5G'></fieldset></dl></div>
                • <tfoot id='ZcM5G'></tfoot>

                      • <bdo id='ZcM5G'></bdo><ul id='ZcM5G'></ul>