【发布时间】:2015-03-01 09:27:46
【问题描述】:
我的视图底部有以下表格视图
它有一个高度约束(优先级 250)和一个对视图底部的约束(优先级 1000)。高度约束指向我的视图控制器中的“IBOutlet”。
我想把table view的高度从44.0f改成7*44.0f,所以我做的就是这个;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.categoriesShown) {
[self hideCategories];
} else {
[self showCategories];
}
self.categoriesShown = !self.categoriesShown;
}
- (void)showCategories
{
self.categoriesHeightConstraint.constant = self.categories.count * 44.0f;
}
- (void)hideCategories
{
self.categoriesHeightConstraint.constant = 44.0f;
}
它工作正常。但是当我尝试使用以下代码为所有这些设置动画时:
- (void)showCategories
{
[self.categoryTableView layoutIfNeeded];
[UIView transitionWithView:self.categoryTableView duration:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{
self.categoriesHeightConstraint.constant = self.categories.count * 44.0f;
[self.categoryTableView layoutIfNeeded];
} completion:nil];
}
- (void)hideCategories
{
[self.categoryTableView layoutIfNeeded];
[UIView transitionWithView:self.categoryTableView duration:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{
self.categoriesHeightConstraint.constant = 44.0f;
[self.categoryTableView layoutIfNeeded];
} completion:nil];
}
然后表格视图和视图底部之间的约束以某种方式被打破,这就是我显示然后隐藏表格视图时得到的结果
有谁知道为什么,约束被打破,但只有当我尝试为更改设置动画时?
更新:UIButton 约束两个按钮都有宽度和高度约束以及对视图底部的约束。左边的按钮对视图有一个前导约束。右边的一个对视图有一个尾随约束。如上所述,它们都对表格视图有水平间距约束。
【问题讨论】:
-
我在没有 2 个按钮的情况下测试了您的布局,并将 tableview 的侧面固定到 superview 并且效果很好。这 2 个按钮发生了什么事。你能展示你所有的约束吗?
-
嗯,这很奇怪。我认为这些限制没有任何问题。我添加了一个屏幕截图。希望对您有所帮助。
-
按钮上方的两条垂直线是什么?
-
它们是按钮和视图之间的前导和尾随约束
-
我什至删除了后面的地图视图和按钮,看看它们是否与问题有关,但我遇到了同样的问题。
标签: ios objective-c xcode interface-builder nslayoutconstraint