UITableViewCell flashing on LongPress

I have it UITableView

and UITableViewCell

I add it UILongPressGestureRecognizer

like this:

// Setup Event-Handling
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTableViewCellLongPress:)];

[cell addGestureRecognizer:longPress];

[longPress setDelegate:self];


I want the cell to blink when the event is fired, and I would also like to disable the standard behavior (when it is clicked blue once).

How can I do this in my handleTableViewCellLongPress




source to share

1 answer

You can use chain animation:

- (UITableViewCell *) tableView:(UITableView *)tableView 
          cellForRowAtIndexPath:(NSIndexPath *)indexPath
  UITableViewCell *cell = ...
  // remove blue selection
  cell.selectionStyle = UITableViewCellSelectionStyleNone; 

  UILongPressGestureRecognizer *gesture = [[[UILongPressGestureRecognizer alloc]    
    initWithTarget:self action:@selector(handleTableViewCellLongPress:)] autorelease];
  [cell addGestureRecognizer:gesture];

  return cell;

- (void) handleTableViewCellLongPress:(UILongPressGestureRecognizer *)gesture
  if (gesture.state != UIGestureRecognizerStateBegan)

  UITableViewCell *cell = (UITableViewCell *)gesture.view;
  [UIView animateWithDuration:0.1 animations:^{
    // hide
    cell.alpha = 0.0;
  } completion:^(BOOL finished) {
    // show after hiding
    [UIView animateWithDuration:0.1 animations:^{
      cell.alpha = 1.0;
    } completion:^(BOOL finished) {





All Articles