您好,当用户向下滚动时,如果用户滚动到顶部,则通常会在没有动画的情况下移动,从而为表格 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/