【发布时间】:2015-02-09 20:31:40
【问题描述】:
UIViewController 与 UIView 和 UITableView
UIView
|-UITableView
我正在尝试这样设置边距:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.layoutMargins = UIEdgeInsetsMake(30, 30, 30, 30);
self.tableView.preservesSuperviewLayoutMargins = YES;
[self.view layoutIfNeeded];
}
但是视图上没有发生任何事情。
这是来自 InterfaceBuilder 的约束
(lldb) po self.view.constraints
<__NSArrayM 0x786ab6e0>(
<NSLayoutConstraint:0x7896e940 UIView:0x7896e470.trailingMargin == UITableView:0x79b51a00.trailing - 16>,
<NSLayoutConstraint:0x7896e970 UITableView:0x79b51a00.leading == UIView:0x7896e470.leadingMargin - 16>,
<NSLayoutConstraint:0x7896e9a0 V:[_UILayoutGuide:0x7896e510]-(0)-[UITableView:0x79b51a00]>,
<NSLayoutConstraint:0x7896e9d0 V:[UITableView:0x79b51a00]-(0)-[_UILayoutGuide:0x7896e600]>,
<_UILayoutSupportConstraint:0x7896c7d0 V:[_UILayoutGuide:0x7896e510(0)]>,
<_UILayoutSupportConstraint:0x7896c2b0 V:|-(0)-[_UILayoutGuide:0x7896e510] (Names: '|':UIView:0x7896e470 )>,
<_UILayoutSupportConstraint:0x7896cbf0 V:[_UILayoutGuide:0x7896e600(0)]>,
<_UILayoutSupportConstraint:0x7896ea00 _UILayoutGuide:0x7896e600.bottom == UIView:0x7896e470.bottom>
)
结果看不到任何边距,什么都没有改变......我在做什么?
iOS 8
【问题讨论】:
-
如果在调用
layoutIfNeeded之前使用setNeedsUpdateConstraints会怎样?我有一种感觉,更改layoutMargins不会将约束标记为脏。 -
见here。有一个非iOS11的解决方案。我只是确定它是否是推荐的......
标签: ios objective-c uitableview ios8 autolayout