0

When the user taps a UITableViewCell I want an image in that cell to make a little bouncing animation to provide user feedback. That animation works exactly like I want except it is not always triggered when I'm tapping a cell. I'm using Facebook POP animation framework.

#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"];
}

Do I need to reset the animation each time a cell is tapped, or anything else I'm missing?

Thanks in advance

user2381011
  • 351
  • 6
  • 21

1 Answers1

0

The problem is that you are creating (or re-using) a cell every time didSelectRowAtIndexPath is called because you are using dequeueReusableCellWithIdentifier. Instead the first line of you implementation should be:

MyCustomCell *cell = (MyCustomCell *)[tableView cellForRowAtIndexPath: indexPath];
combinatorial
  • 9,132
  • 4
  • 40
  • 58
  • When I implement your method, the cell isn't making a bounce animation at all. I want to see the animation each time a tap a cell. After setting the velocity to 100 I see an animation turning my image upside down and animating very random. Strange... – user2381011 Mar 17 '15 at 18:02
  • A very large velocity probably causes scale to go negative which will flip it. Try some values between 5 and 100. – combinatorial Mar 17 '15 at 23:11