【发布时间】:2015-07-15 09:13:56
【问题描述】:
我有一个视图,它有一个 UILabel、一个 UITableView(tblFilters) 和一个 UIView(btnBaseView)(to保留其他三个 UIButtons)。请检查下图:-
我需要扩展tblFilters 的高度以展示每个类别的选项,但需要使btnBaseView 始终在屏幕上可见。所以基本上tblFilters 高度不应该超过限制。
为了实现这一点,我对btnBaseView 应用了一个高度约束,并赋予它必需优先级。同样,tblFilters 有一个高度限制,但有 DefaultHigh 优先级。
// Height Constraint of btnBaseView. Height Should always be >=116
btnSectionHeightConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[btnBaseView(>=116)]" options:0 metrics:nil views:@{@"btnBaseView":btnBaseView}];
[[btnSectionHeightConstraint firstObject] setPriority:UILayoutPriorityRequired];
[self addConstraints:btnSectionHeightConstraint];
// TableView Height Constraint. Height value is being changed when user click on "+" button of table section.
tableHeightConstraints = [NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:[tblFilters(>=%f)]",176.0] options:0 metrics:nil views:@{@"tblFilters":tblFilters}];
[[tableHeightConstraints firstObject] setPriority:UILayoutPriorityDefaultLow];
[self addConstraints:tableHeightConstraints];
但是这个方案似乎不起作用,因为 tableView 覆盖了整个 baseView 并将btnBaseView 推到了可见区域之外。
我也尝试将 DefaultLow 优先级保持为 tblFilters,但没有效果。当我在更改tblFilters 高度约束后调试代码时,它会在控制台中打印正确的优先级输出,但对视图没有影响。
有人可以帮我找出约束优先级没有按预期工作的问题,还是我对这个概念有错误的理解。任何帮助表示赞赏。
【问题讨论】:
标签: ios objective-c autolayout constraints