UITableViewCell мигает на LongPress - PullRequest
3 голосов
/ 09 марта 2012

У меня есть UITableView, а к UITableViewCell s я добавляю UILongPressGestureRecognizer, например:

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

[cell addGestureRecognizer:longPress];

[longPress setDelegate:self];

Я хотел бы, чтобы ячейка мигала при срабатывании события, и я также хотел бы запретить стандартное поведение (когда при однократном нажатии оно становится синим).

Как я могу сделать это в моем handleTableViewCellLongPress -методе?

Спасибо!

1 Ответ

4 голосов
/ 09 марта 2012

Вы можете использовать анимацию цепочки:

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

    }];
  }];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...