iOS - TableView willDisplayCell 动画仅在用户向下滚动而不是顶部时发生

标签 ios objective-c uitableview animation tableview

您好,当用户向下滚动时,如果用户滚动到顶部,则通常会在没有动画的情况下移动,从而为表格 View 单元格设置动画。

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cells forRowAtIndexPath:(NSIndexPath *)indexPath{
    cells.alpha = 0.0;
    [UIView animateWithDuration:0.4 animations:^{
        cells.alpha = 1.0;
    }];
}

我试过这样但是动画一直在发生

最佳答案

创建一个带有 Bool 属性“isAnimated”的自定义单元格。默认情况下,“isAnimated”值为“NO”。

并在 willDisplayCell:(UITableViewCell *)cell 方法中更改代码。

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//Typecast UITableViewCell to CustomCell. ex: CustomCell *objCell = (CustomCell *)cell
// check isAnimated or not 
   if(cell.isAnimated) return;
   cell.alpha = 0.0;
   [UIView animateWithDuration:0.4 animations:^{
      cell.alpha = 1.0;
      cell.isAnimated = YES;
   }];
}

这里的Cell reference是Custom Cell reference。我希望这段代码对你有用

关于iOS - TableView willDisplayCell 动画仅在用户向下滚动而不是顶部时发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40337028/

相关文章:

ios - 单击按钮后跳转到该详细信息时,如何为 UITableViewCell 创建详细信息?

objective-c - 将选定的日期和时间保存到plist中

ios - 在 iTunes Connect 上提交应用内购买详情以供审核

ios - 错误 : Linker command failed: duplicate symbol for architecture x86_64

iphone - HTML 电子邮件在从 iPhone 程序发送后丢失格式

iPhone SDK : Setting the size of UISearchDisplayController's table view

ios - NSPredicate 与 NSURL 在 iOS 中崩溃

ios - iPhone SDK 系统提供的按钮和图标

ios - 快速组合 : `first(_ n: Int)` equivalent to RxSwift `take(_ n: Int)` ?

objective-c - 当你运行 self=[super init] 并且它返回 nil 时,正确的 react 是什么?