Ios cellForRowAtIndexPath动画在滚动/重画时再次触发
“我的单元格”中的某些标签具有下面的动画外观代码 然而,一旦屏幕上的单元格多于房间,滚动之前插入的单元格就会被重新绘制,并再次触发其动画 如何防止这种行为Ios cellForRowAtIndexPath动画在滚动/重画时再次触发,ios,cocoa-touch,Ios,Cocoa Touch,“我的单元格”中的某些标签具有下面的动画外观代码 然而,一旦屏幕上的单元格多于房间,滚动之前插入的单元格就会被重新绘制,并再次触发其动画 如何防止这种行为 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdent
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"results"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"results"];
}
...
// Animations
nameLabel.alpha = 0;
nameLabel.transform = CGAffineTransformMakeTranslation(-80, 0);
priceLabel.alpha = 0;
priceLabel.transform = CGAffineTransformMakeTranslation(+100, 0);
cell.imageView.alpha = 0;
cell.imageView.transform = CGAffineTransformMakeTranslation(-300, 0);
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
nameLabel.alpha = 1;
nameLabel.transform = CGAffineTransformMakeTranslation(0, 0);
priceLabel.alpha = 0.6;
priceLabel.transform = CGAffineTransformMakeTranslation(0, 0);
cell.imageView.alpha = 1;
cell.imageView.transform = CGAffineTransformMakeTranslation(0, 0);
}completion:^(BOOL Finished){}];
return cell;
}
也许您可以在collectionView:willDisplayCell:forItemAtIndexPath:中设置单元格的动画,当单元格出现时,将调用该动画,而不是CellForRowtIndexPath: