【问题标题】:CABasicAnimation is removed in a UITableView在 UITableView 中删除 CABasicAnimation
【发布时间】:2011-10-12 16:57:38
【问题描述】:

我有一个填充一些单元格的 UITable 视图。

很少有细胞具有旋转图像。图像使用动画旋转:

[image.layer removeAllAnimations];
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.duration = 1.0;
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 * 1.0 * rotationAnimation.duration ];
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF; 
[image.layer addAnimation:rotationAnimation forKey:nil];

由于某种原因,并非所有图像都有动画。似乎当我开始滚动表格时,一些动画被删除/禁用了。

由于某种原因

【问题讨论】:

  • 你在哪里制作动画?你知道 UITableView 重用了它的单元格吗?您知道单元重用机制的工作原理吗?
  • 此代码正在由单元格项目的方法执行。我在重用(或创建)一个单元格后调用它。在 cellForRowAtIndexPath: MyCell* cell={dequeue or create new cell}; [单元格动画];
  • 你有没有得到任何地方?

标签: iphone uitableview animation sdk caanimation


【解决方案1】:

将最后一行更改为使用随机键:

[image.layer addAnimation:rotationAnimation forKey:[NSString stringWithFormat:@"%d", arc4random()]];

这在我的情况下解决了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2017-03-02
    • 1970-01-01
    相关资源
    最近更新 更多