Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell blink on LongPress

I've got an UITableViewand to its UITableViewCells I'm adding a UILongPressGestureRecognizerlike this:

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

[cell addGestureRecognizer:longPress];

[longPress setDelegate:self];

I would like the cell to blink when the event is fired and I also would like to forbid the standard behaviour (that it turns blue when pressed once).

How can I do this in my handleTableViewCellLongPress-Method?

Thanks!

like image 668
Finn 'EphK' DuWeisst Avatar asked Dec 05 '25 11:12

Finn 'EphK' DuWeisst


1 Answers

You could use chaining animations:

- (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)
    return;

  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) {

    }];
  }];
}
like image 60
Shiki Avatar answered Dec 07 '25 00:12

Shiki