我在 UITableViewDelegate
中运行了一些非常简单的代码。方法tableView:willDisplayCell:forRowAtIndexPath:
如此处所示:
[interestCell.imageView setAlpha:0.0];
[interestCell.textLabel setAlpha:0.0];
[interestCell setFrame:CGRectMake(self.view.frame.size.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
CGFloat delayForCellAnimation = ((indexPath.row+1)+(indexPath.section+1))*0.15f;//((indexPath.row+1)+(indexPath.section+1))*0.2f+0.5f;
NSLog(@"delay: %f", delayForCellAnimation);
[interestCell setFrame:CGRectMake(self.view.frame.size.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
[UIView animateWithDuration:0.5f delay:delayForCellAnimation options:UIViewAnimationOptionAllowAnimatedContent animations:^{
[interestCell.imageView setAlpha:0.6];
[interestCell.textLabel setAlpha:0.6];
[interestCell setFrame:CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
} completion:^(BOOL finished) {
[interestCell setHasAnimatedIn:YES];
[UIView animateWithDuration:0.2 animations:^{
[interestCell.imageView setAlpha:1.0];
[interestCell.textLabel setAlpha:1.0];
}];
}];
我想要做的是从表格 View 的右侧为所有单元格设置动画。这目前正在工作,但我希望单元格延迟动画,以便顶部单元格可以在底部单元格之前飞入。我正在使用上面的动画 block 并计算延迟,我将其记录到控制台并且它确实计算正确(表中稍后的条目的值更大),但是当我运行应用程序时动画不会发生延迟.有什么想法吗?谢谢你。
最佳答案
实现 UITableView
可能更容易。 - 带有 UICollectionView
的 Controller 和自定义布局。然后您可以使用
- initialLayoutAttributesForAppearingItemAtIndexPath:
将单元格放置在屏幕外并让 Collection View 将它们动画到它们的真实位置(由
- layoutAttributesForItemAtIndexPath:
给出)。
如果一个子类 UICollectionViewFlowLayout
没有为您实现足够的表格 View 功能(例如,粘性标题),您应该看看 CSStickyHeaderFlowLayout
.
关于iOS UITableViewCell 动画延迟加载不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24268121/