Facebook POP:UITableViewCell动画并不总是有效

时间:2015-03-14 10:03:04

标签: objective-c facebook-pop

当用户点击UITableViewCell时,我希望该单元格中的图像能够制作一个小的弹跳动画来提供用户反馈。这个动画完全像我想要的那样,但是当我点击一个单元格时它并不总是被触发。我正在使用Facebook POP动画框架。

#import <POP/POP.h>

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customcell" forIndexPath:indexPath];

    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];
    scaleAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1,1)];
    scaleAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(5,5)];
    scaleAnimation.springBounciness = 20.f;

    [cell.bounceimage pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"];
}

每次点击一个单元格,还是我缺少的任何其他内容时,是否需要重置动画?

提前致谢

1 个答案:

答案 0 :(得分:0)

问题在于,每次调用didSelectRowAtIndexPath时都会创建(或重新使用)单元格,因为您使用的是dequeueReusableCellWithIdentifier。相反,您实现的第一行应该是:

MyCustomCell *cell = (MyCustomCell *)[tableView cellForRowAtIndexPath: indexPath];