让我试着解释一下我遇到的问题:
工作(但不完整)设置如下:
我有一个UITableView,每边都有4个约束
对于那个UITableView,我使用以下代码添加一个具有恒定高度的tableViewHeader:
HeaderView *header = [[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil] objectAtIndex:0];
self.tableView.tableHeaderView = header;
[header setNeedsLayout];
[header layoutIfNeeded];
self.tableView.tableHeaderView = nil;
[header removeFromSuperview];
CGFloat height = [header systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect headerFrame = header.frame;
headerFrame.size.height = height;
header.frame = headerFrame;
self.tableView.tableHeaderView = header;
标题包含一个带有4个约束的图像视图(每边一个,常量为10)和一个高度约束,以确保图像视图的高度不变。
现在,这可以按预期工作,但状态栏显示在标题的顶部,看起来不是很干净。我想拥有的是状态栏,然后从它开始,以便它们保持独立。为了达到这个目的,我想我会使用Topview Guide.Bottom将Superview的UITableView的顶级约束修改为UITableView。
这似乎是一个好主意,但在运行时,Xcode并没有发现它非常有趣并打破了这个新约束导致同样的问题,状态栏超过了headerview:
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:0x7faf3253a990 V:[_UILayoutGuide:0x7faf32535650]-(0)-[UITableView:0x7faf33004000]>",
"<_UILayoutSupportConstraint:0x7faf32539f30 V:[_UILayoutGuide:0x7faf32535650(20)]>",
"<_UILayoutSupportConstraint:0x7faf32539ed0 V:|-(0)-[_UILayoutGuide:0x7faf32535650] (Names: '|':UIView:0x7faf32538310 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7faf324cf050 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7faf32538310] (Names: '|':UIWindow:0x7faf3273b9a0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7faf3253a990 V:[_UILayoutGuide:0x7faf32535650]-(0)-[UITableView:0x7faf33004000]>
我尝试过使用拥抱/压缩/优先级但尚未解决此问题。你们能告诉我这里没有看到什么吗?