ios - UIView animateWithDuration UITableView 导致 UITableViewCell subview 也有动画

标签 ios objective-c iphone uitableview

我正在尝试使用 动画更改 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];
    }];
}

animation

最佳答案

//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/

相关文章:

iphone - iOS - CAKeyFrameAnimation - 不播放

iphone - 如何在 objective-c 中使用bool变量

iOS block 设计 : Nested Blocks With Return Values?

ios - SDNestedTable 扩展在 iOS 7 上不起作用

ios - 无法调用 'saveInBackgroundWithBlock'

ios - 对多个容器设置约束

iphone - 我应该将启动图像 "Default.png"放在 iPhone 应用程序的项目目录中的什么位置?

ios - 当我在 View Controller 中移动时保存文本字段的值

objective-c - UIPickerView背景颜色没有改变?

ios - 在对象UiTableViewCell上找不到属性