我正在尝试使用 动画更改 UITableView 高度约束
+ transitionWithView:duration:options:animations:completion:
。设置选项后,UITableViewCell contentView 的 subview UIView 也会进行动画处理。效果如下图。如您所见,窗口下方的单元格上升,红点 View 的边界根据预定义的约束进行动画处理。如果我不设置动画选项,就不会是这个样子。但是当我改变 UITableView 高度时我需要动画。那么如何保持表格 View 高度动画和禁用表格 View 单元格contentView的 subview 动画呢?代码如下。红点 View 是具有红色背景颜色的 UIView。有什么方法可以禁用 UITableViewCell contentView 的 subview 动画吗?
- (void)changeTableViewHeight {
self.tableViewTopVerticalSpaceConstraint.constant = 0;
[self.tableView setNeedsUpdateConstraints];
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.topViewHeightConstraint.constant = 50;
[self.topView setNeedsUpdateConstraints];
}];
}
最佳答案
//1. All constraints change must be done
self.hightConstraint.constant = 200;
self.anotherConstraint.constant = 34;
...
...
// 2. Indimate to iOS that this view need update constraints.
// Hey iOS I have modified few constraints. beware of it to layout that changes.
[self.view setNeedsUpdateConstraints];
// 3. I'm done, relayout the view with animation,
If I really changed any constraints to view.
[UIView animateWithDuration:1.5 animations:^{
[self.view layoutIfNeeded];
}];
希望有人能节省他们的时间
关于ios - UIView animateWithDuration UITableView 导致 UITableViewCell subview 也有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30914166/