iOS UITableViewCell 动画延迟加载不起作用

标签 ios objective-c uitableview

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

相关文章:

ios - 更新 TableViewCell 中的 UIButton State 会改变其他行

ios - 是否可以在应用程序加载数据并卡住时显示警报?

ios - 我想用短信给电话发短信,但让它在短信完成后把人送回去,比如 "telprompt"但对于短信

ios - oDesk Contractors 的 iOS 开发新手 - 如何接收完成的应用程序?

ios - 更改 ViewController 后场景转换不再工作

ios - Swift 优化级别 'Fastest' 中断数组排序

ios - FBSDKShareKit : Share Form does not prompt

ios - 用户界面测试。如何检查键盘是否存在?

iphone - 如何动态读取和更改 UILabel 的字体大小?

ios - UITableView:在初始滚动时使用自定义/可变单元格高度滚动到底部不准确