ios - UIView layoutConstraint 奇怪的行为,粘在上面
问题描述
我有一个表视图作为子视图(contentView 是超级视图)。它有一个值为 190 的顶部约束,但在我的 iPhone 6 上它一直保持在顶部(origin.y 为 0.0)。但是,在我的 iPhone X 上,它完全正常。
- (void)adjustHeightOfViews {
//adjust contentview-height to tableview-height
self.tableViewTopConstraint.active = YES;
self.tableViewTopConstraint.constant = 190;
self.tableViewHeightConstraint.constant = 0.0f;
for (int i = 0; i < [_cellTitles count]; i ++) {
self.tableViewHeightConstraint.constant += [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]].size.height;
}
self.contentViewHeightConstraint.constant = self.tableViewHeightConstraint.constant + 500.0f;
self.tableViewTopConstraint.constant = 190;
}
viewheights 在我的 adjustHeightOfViews 方法中设置,我在 viewDidLayoutSubviews 中调用该方法(我在这里尝试在 viewDidAppear 和其他任何地方调用该方法,但不能解决问题)。
这里有什么问题?
编辑
当我在我的 cellForRow 中禁用 [celllayOutIfNeeded] 时问题就消失了(我当然需要它),太奇怪了!
-> 之后 tableView 有一个正常工作的 topConstraint
解决方案
推荐阅读
- ios - PushKit 不能在被杀死的状态下工作 swift IOS
- c++ - FastLED,如何在运行时更改 LED 的数量(NUM_LEDS)?
- excel - Excel提取多个匹配的行
- ios - Swift:JSON 解析未显示在 UILabel 中,但可以使用 Alamofire 在输出窗口中看到
- ruby - RubyMine 2018.1.3 - 无法在 Mac OS X 10.13.4 中配置 Ruby 解释器
- angular - 在应用程序中始终保持登录状态,当我关闭应用程序时,使用 Nativescript 中的 Http 重新启动、关闭移动设备等
- javascript - 向原型添加方法
- groovy - Stubbed method should return value depending on given mock parameter in Spock
- three.js - 如果我加载一个新的 dicom 文件,内存会不断增长
- c# - 按钮单击时方法的并行执行