Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios cellForRowAtIndexPath动画在滚动/重画时再次触发_Ios_Cocoa Touch - Fatal编程技术网

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: