简体   繁体   English

iOS 8 xib + AutoLayout对于tableViewHeaderView无法正常工作

[英]iOS 8 xib + AutoLayout not working correctly for tableViewHeaderView

I have a xib file with a UIView that I want to use as a tableViewHeaderView. 我有一个带有UIView的xib文件,我想用作tableViewHeaderView。 The view has a label with a bunch of text. 该视图具有带有一堆文本的标签。 No matter what I try I cannot get it to adjust so the height fits in correctly according to the constraints. 不管我尝试什么,都无法对其进行调整,因此高度无法根据约束正确地放置。

This is the nib: 这是笔尖: 在此处输入图片说明

The label is set to adjust its height to fit the text and all the margins are 15 points away from the superview. 标签设置为调整其高度以适合文本,并且所有边距均距超级视图15个点。 However when this is added to the table view it looks like this: 但是,将其添加到表视图时,它看起来像这样:

在此处输入图片说明

I can't seem to figure out what I'm missing, here is the sample project , is there some way you are supposed to setup the nib to allow the view to be sized by its contents constraints? 我似乎无法弄清楚我缺少的什么, 这是示例项目 ,是否应该以某种方式设置笔尖以允许按其内容限制来调整视图大小?

Edit: I've tried the answer given here with no luck: https://stackoverflow.com/a/21099430/383603 编辑:我没有运气就尝试过这里给出的答案: https : //stackoverflow.com/a/21099430/383603

Edit 2: It should look like this: 编辑2:应该看起来像这样:

在此处输入图片说明

It looks like that for the tableViewHeaderView view, the actually height is taken from the xib file, which is 570 in your case. 看起来对于tableViewHeaderView视图,实际高度是从xib文件获取的,在您的情况下为570。 If that is true the auto layout system should get an unambiguous state: 如果是这样,则自动布局系统应获得明确的状态:

  • vertical hugging priority is 1000 which is the highest and in order to get that working 垂直拥抱优先级为1000,这是最高优先级
  • it needs to break the 15 top or 15 bottom point constraint 它需要突破15个最高点或15个最低点约束
  • or resize your header dynamically 或动态调整标题大小

Based on how your pictures look like, it's most likely that the runtime system decided to break the vertical hugging priority to keep everything else valid 根据图片的外观,运行时系统很可能决定打破垂直拥抱优先级以保持其他所有内容有效

Possible solutions might be: 可能的解决方案可能是:

  • Change the height of the header dynamically 动态更改标题的高度
  • Change (lower) the priority of top and/or bottom constraint 更改(降低)最高和/或最低约束的优先级

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

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