使用自动布局更改带有动画的表格视图框架

Changing tableview frames with animation using autolayout

我正在尝试通过在 animationWithDuration 块中使用自动布局来更改 tableview 框架。像那样;

[UIView animateWithDuration:0.3f animations:^{

            weekdayOffersVerticalConstraint.constant = 80;
            [headerView layoutIfNeeded];
            [weekdayTableView layoutIfNeeded];

            self.isTableViewSmall = YES;

        } completion:^(BOOL finished) {


        }];

我的 tableview 的框架随着这个代码块而改变,但是当我向下滚动时,单元格从左侧到右侧,我认为它与 [weekdayTableView layoutIfNeeded]; layoutIfNeeded 对所有子视图的影响有关。我怎样才能阻止影响我的 tableview 的单元格?

抱歉我的英语不好,非常感谢您的回答和建议。

在开始动画更新约束之前调用 layoutIfNeeded

[headerView layoutIfNeeded];
[weekdayTableView layoutIfNeeded];
[UIView animateWithDuration:0.3f animations:^{

            weekdayOffersVerticalConstraint.constant = 80;
            [headerView layoutIfNeeded];
            [weekdayTableView layoutIfNeeded];

            self.isTableViewSmall = YES;

        } completion:^(BOOL finished) {
            //
        }];

您可能也不希望在动画块中设置 BOOL 属性 除非您有一种方法可以在动画期间故意覆盖它。