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

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

      1. 具有动态 tableView 高度的模糊布局

        Ambiguous layout with dynamic tableView height(具有动态 tableView 高度的模糊布局)
          <tbody id='FIX4A'></tbody>

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

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

              • <tfoot id='FIX4A'></tfoot>
                  <bdo id='FIX4A'></bdo><ul id='FIX4A'></ul>
                  本文介绍了具有动态 tableView 高度的模糊布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 viewController,我想在里面有两个 1 tableView 和 1 childViewController.

                  I have a viewController and I want to have two 1 tableView and 1 childViewController inside it.

                  • tableView 不可滚动,具有动态单元格高度.(我使用的是 tableView,所以我可以折叠行)
                  • childVC 是具有动态单元格高度的可滚动 tableView.

                  我的约束如下:

                  NSLayoutConstraint.activate([
                     tableView.topAnchor.constraint(equalTo: view.topAnchor),
                     tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
                     tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
                     tableView.bottomAnchor.constraint(equalTo: artistVC.view.topAnchor),
                  
                  ])
                  
                  NSLayoutConstraint.activate([
                     artistVC.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
                     artistVC.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
                     artistVC.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
                  ])
                  

                  当我这样设置时,只有 childVC 显示在屏幕上.我没有看到 tableView. 我想让 tableView 尽可能多地展开,然后让 childVC 可滚动到底部.

                  When I setup this way, only the childVC shows on the screen. I don’t see the tableView. I want to allow the tableView to expand as much as it needs and then let the childVC be scrollable to the bottom.

                  • 对于我得到的 tableView:高度和可滚动内容大小不明确
                  • 对于 childVC 的观点,我得到:高度和垂直位置不明确

                  但是我不能自己设置高度,因为我不知道 tableViewCell 的高度是多少..

                  However I can't set the height myself as I don't know what the height of the tableViewCell is..

                  有什么建议吗?我已经尝试更改内容拥抱和内容压缩阻力,但我没有找到任何运气.

                  Any suggestions? I've tried changing the content hugging and content Compression Resistance but I didn't find any luck there.

                  推荐答案

                  我建议像这样子类化 UITableView:

                  I suggest subclassing UITableView like this:

                  class AutomaticHeightTableView: UITableView {
                  
                    override var intrinsicContentSize: CGSize {
                      return contentSize
                    }
                  
                    override func reloadData() {
                      super.reloadData()
                      invalidateIntrinsicContentSize()
                    }
                  }
                  

                  然后在 Interface Builder 中将 AutomaticHeightTableView 设置为表格视图的类,表格将尝试调整自身大小以适应内容.它将遵循您放置的任何其他约束,因此请确保约束允许它自由增长.

                  Then in Interface Builder set AutomaticHeightTableView as the class to your table view and the table will try to size itself to fit the content. It will follow any other constraints you placed so make sure the constraints allow it to grow freely.

                  这篇关于具有动态 tableView 高度的模糊布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

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

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

                      1. <legend id='IIHMN'><style id='IIHMN'><dir id='IIHMN'><q id='IIHMN'></q></dir></style></legend>

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