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

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

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

      2. <tfoot id='QlPCL'></tfoot>

        什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height&quo

        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屋-程序员
        <tfoot id='UdabS'></tfoot>

        • <legend id='UdabS'><style id='UdabS'><dir id='UdabS'><q id='UdabS'></q></dir></style></legend>

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

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

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

                    <tbody id='UdabS'></tbody>
                • 本文介绍了什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height"?我应该如何强制它干净地重新计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个在 iOS 8 下运行的 UITableView,我正在使用情节提要中约束的自动单元格高度.

                  I have a UITableView running under iOS 8 and I'm using automatic cell heights from constraints in a storyboard.

                  我的一个单元格包含一个 UITextView,我需要它根据用户输入收缩和扩展 - 点击以收缩/扩展文本.

                  One of my cells contains a single UITextView and I need it to contract and expand based on user input - tap to shrink/expand the text.

                  我通过向文本视图添加运行时约束并更改约束上的常量以响应用户事件来做到这一点:

                  I'm doing this by adding a runtime constraint to the text view and changing the constant on the constraint in response to user events:

                  -(void)collapse:(BOOL)collapse; {
                  
                      _collapsed = collapse;
                  
                      if(collapse)
                          [_collapsedtextHeightConstraint setConstant: kCollapsedHeight]; // 70.0
                      else
                          [_collapsedtextHeightConstraint setConstant: [self idealCellHeightToShowFullText]];
                  
                      [self setNeedsUpdateConstraints];
                  
                  }
                  

                  每当我这样做时,我都会将其包装在 tableView 更新中并调用 [tableView setNeedsUpdateConstraints]:

                  Whenver I do this, I wrap it in tableView updates and call [tableView setNeedsUpdateConstraints]:

                  [tableView beginUpdates];
                  
                  [_briefCell collapse:!_showFullBriefText];
                  
                  [tableView setNeedsUpdateConstraints];
                  // I have also tried 
                  // [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
                  // with exactly the same results.
                  
                  [tableView endUpdates];
                  

                  当我这样做时,我的单元格确实会扩展(并在执行此操作时动画)但我收到约束警告:

                  When I do this, my cell does expand (and animates whilst doing it) but I get a constraints warning:

                  2014-07-31 13:29:51.792 OneFlatEarth[5505:730175] Unable to simultaneously satisfy constraints.
                  
                  Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
                  
                  (
                  
                      "<NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>",
                  
                      "<NSLayoutConstraint:0x7f94dced2260 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...']-(15)-|   (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
                  
                      "<NSLayoutConstraint:0x7f94dced2350 V:|-(6)-[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...']   (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
                  
                      "<NSLayoutConstraint:0x7f94dced6480 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f94de5773a0(91)]>"
                   )
                  
                  Will attempt to recover by breaking constraint 
                  
                  <NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>
                  

                  388 是我计算的高度,UITextView 上的其他约束来自 Xcode/IB.

                  388 is my calculated height, the other constraints on the UITextView are mine from Xcode/IB.

                  最后一个困扰着我 - 我猜 UIView-Encapsulated-Layout-Height 是第一次渲染时计算出的单元格高度 - (我设置了我的 UITextView height to be >= 70.0) 但是这个派生的约束然后推翻更新的用户 cnstraint 似乎不正确.

                  The final one is bothering me - I'm guessing that UIView-Encapsulated-Layout-Height is the calculated height of the cell when it is first rendered - (I set my UITextView height to be >= 70.0) however it doesn't seem right that this derived constraint then overrules an updated user cnstraint.

                  更糟糕的是,虽然布局代码说它试图打破我的高度限制,但它没有 - 它继续重新计算单元格高度,并且一切都按照我的意愿绘制.

                  Worse, although the layout code says it's trying to break my height constraint, it doesn't - it goes on to recalculate the cell height and everything draws as I would like.

                  那么,什么是 NSLayoutConstraint UIView-Encapsulated-Layout-Height (我猜这是自动调整单元格大小的计算高度),我应该怎么做强制它干净地重新计算?

                  So, what is NSLayoutConstraint UIView-Encapsulated-Layout-Height (I'm guessing it is the calculated height for automatic cell sizing) and how should I go about forcing it to recalculate cleanly?

                  推荐答案

                  尝试将 _collapsedtextHeightConstraint 的优先级降低到 999.这样系统提供了 UIView-Encapsulated-Layout-Height 约束总是优先的.

                  Try to lower the priority of your _collapsedtextHeightConstraint to 999. That way the system supplied UIView-Encapsulated-Layout-Height constraint always takes precedence.

                  它基于您在 -tableView:heightForRowAtIndexPath: 中返回的内容.确保返回正确的值和您自己的约束,并且生成的约束应该相同.您自己的约束的较低优先级仅在临时需要以防止在折叠/展开动画运行时发生冲突.

                  It is based on what you return in -tableView:heightForRowAtIndexPath:. Make sure to return the right value and your own constraint and the generated one should be the same. The lower priority for your own constraint is only needed temporarily to prevent conflicts while collapse/expand animations are in flight.

                  补充:虽然系统提供的约束是否正确可能存在争议,但与框架抗争是没有意义的.只需接受系统约束优先.如果您认为系统约束错误,请确保从委托中返回正确的 rowHeight.

                  这篇关于什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height"?我应该如何强制它干净地重新计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 导致跳跃滚动)
                  quot;Auto Layout still required after executing -layoutSubviewsquot; with UITableViewCell subclass(“执行 -layoutSubviews 后仍需要自动布局带有 UITableViewCell 子类)

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

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

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