【发布时间】:2015-07-21 18:48:17
【问题描述】:
在我的 tableview 中,当 tableview 重新加载其数据时,我需要为每个单元格的 UI 设置动画。
这需要自定义动画,而不仅仅是淡入淡出或默认过渡。
例如,当点击“编辑”按钮时,在我看来,表格视图会重新加载,并且每个单元格都会针对这种新的编辑模式更新其 UI。
但是,在此重新加载期间,我尝试使用 UIView 动画块来更新单元格中 UILabel 的约束,但它不会动画。
这是我在 tableview 上调用 reloadData 时运行的代码。这是在cellForRowAtIndexPath 方法中调用的。
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^
{
//does not animate
_lblContainerLeftConstraint.constant = 18;
[self setNeedsLayout];
//does animate
_reorderIcon.alpha = 0.5f;
} completion:nil];
【问题讨论】:
-
我认为您需要在
willDisplayCell中执行此操作。在动画块之前设置新的约束值并调用[cell.contentView setNeedsLayout]。然后在动画块中添加[cell.contentView layoutIfNeeded],它应该在您的时间段内为约束更改设置动画。 -
成功了!谢谢@RoryMcKinnel 在下面留下一个官方答案,如果你愿意,我会给你打勾。
-
很高兴它成功了。作为答案发布。
标签: ios objective-c uitableview uiviewanimation