【发布时间】:2016-04-01 03:16:06
【问题描述】:
我有一个 UITableView 显示单元格。我正在使用自动布局。在某些时候,我将单元格添加到我的 tableView 的一部分中,并且一旦单元格可见,我需要为每个单元格的子视图设置动画。
我编写了以下方法来为单元格的内容设置动画:
- (void)animateWithPercentage:(NSNumber *)percentage
{
self.progressViewWidthConstraint.constant = [percentage intValue];
[self.progressView setNeedsUpdateConstraints];
[UIView animateWithDuration:0.6f animations:^{
[self.progressView layoutIfNeeded];
}];
}
该方法按预期工作,但我不知道何时调用它。
如果我在调用 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 时调用它,我最终会为单元格的整个布局设置动画,因为单元格之前没有自己布局。
我也尝试在layoutSubviews 中调用它,但动画被跳过了。我想现在做动画还为时过早。
知道我的方法应该在哪里调用吗?
【问题讨论】:
标签: ios objective-c uitableview autolayout