UIView-Encapsulated-Layout-Width/Height限制为零 [英] UIView-Encapsulated-Layout-Width / Height Constrained to Zero
问题描述
关于UITableView
单元格和节页眉/页脚的自动布局,存在许多堆栈溢出问题,这些问题涉及UIView-Encapsulated-Layout-Width
约束,UITableView
用于使其组件具有正确的大小:
- 什么是NSLayoutConstraint"UIView-Encapsulated-Layout-Height"以及如何强制它重新进行干净计算
- 自定义键盘中的iOS 8.3'UIView-Encapsulated-Layout-Width'
- 自动布局:是什么创建了名为UIView-Encapsulated-Layout-Width&身高?
- 什么是"UIView-Encapsulated-Layout-Width"约束?
这些约束的目的似乎很明确–它们允许UITableView
和UICollectionView
与约束布局进行交互,并传递其有关应该有多大单元格(和其他组件)的规范.
大多数问题似乎是人们具有一组必需约束,这些约束与这些封装约束不兼容,并且也需要大小为0
.最可行的答案似乎是将用户定义的约束的优先级降低至999
,以便框架可以推翻这些约束.
但是–我感兴趣的理解是为什么 UITableView
要求其中一个视图的宽度为0
? 这是一个错误吗?还是不正确使用的结果?还是说得通?
0
的高度限制有时会很有意义.降低优先级是解决此问题的好方法.但是,为什么单元格的宽度为0
??
UIView没有固有的大小,因此需要宽度和高度限制. UIView-Encapsulated-Layout-Width 和 UIView-Encapsulated-Layout-Height 最初是由UICollectionView/UITableView创建的.然后,根据sizeForItem或heightForRowAtIndexPath委托方法设置约束常量.为了确保在cellForItem/cellForRow方法中创建的UICollectionViewCell/UITableViewCell具有确切的大小.
There are a number of stack overflow questions about auto-layout of UITableView
cells and section headers / footers that concern the UIView-Encapsulated-Layout-Width
constraints that the UITableView
uses to make its components be the correct size:
- what is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly
- iOS 8.3 'UIView-Encapsulated-Layout-Width' in Custom Keyboard
- Auto-layout: What creates constraints named UIView-Encapsulated-Layout-Width & Height?
- What is a 'UIView-Encapsulated-Layout-Width' constraint?
The purpose of these constraints seems pretty clear – they allow the UITableView
and also UICollectionView
to interface with constraint layout and pass in its specification about how large cells (and other components) should be.
Most issues seem to be that people have a set of required constraints that are incompatible with these encapsulation constraints also requiring a size of 0
. The most workable answers seem to be to lower the priority of user defined constraints to 999
so that the framework's can overrule them.
However – what I'm interested in understanding is why is UITableView
requiring a width of 0
for one of its views? Is this a bug? Or is it a results of incorrect use? Or does it make perfect sense?
Height constraints of 0
sometimes make sense, if cells are being expanded from nothing. Lowering priorities is a good way to handle this. But why would the cells be getting a width of 0
?
UIView doesn't have the intrinsic size hence width and height constraints needed. UIView-Encapsulated-Layout-Width and UIView-Encapsulated-Layout-Height are created by UICollectionView / UITableView initially. And later on sets the constraint constant based to the sizeForItem or heightForRowAtIndexPath delegate method. To ensure that UICollectionViewCell / UITableViewCell created in cellForItem / cellForRow method will be having the exact size.
这篇关于UIView-Encapsulated-Layout-Width/Height限制为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!