このアニメーションは、対応するセルを再利用すると削除されるようです。少なくとも、animationDidStop
デキューされたセルを から返したときにデリゲートのコールバックを取得しましたcellForItemAtIndexPath
。
私が思い付くことができる最も簡単な回避策:
テーブル ビューのデータ ソース:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell && [cell conformsToProtocol:@protocol(CustomCellProtocol)])
{
[(id<CustomCellProtocol>)cell beforeDisplayed];
}
return cell;
}
あなたのセル:
static NSString* const kSpinAnimationKey = @"SpinAnimation";
@interface CustomCell () <CustomCellProtocol>
@end
@implementation CustomCell
-(void)startSpinAnimation
{
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: M_PI * 2.0];
animation.duration = 1.0f;
animation.repeatCount = INFINITY;
[self.layer addAnimation:animation forKey:kSpinAnimationKey];
}
-(void)beforeDisplayed
{
UIView* animatedView = self.contentView;
if(![animatedView.layer animationForKey:kSpinAnimationKey])
{
[self startSpinAnimation];
}
}