UITableViewCell在LongPress上闪烁

时间:2012-03-09 10:51:28

标签: ios uitableview

我有UITableViewUITableViewCell我正在添加UILongPressGestureRecognizer这样的内容:

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

[cell addGestureRecognizer:longPress];

[longPress setDelegate:self];

我希望在事件被触发时单元格会闪烁,我也想禁止标准行为(按下一次它会变成蓝色)。

我如何在handleTableViewCellLongPress - 方法?

中执行此操作

谢谢!

1 个答案:

答案 0 :(得分:4)

您可以使用链接动画:

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

    }];
  }];
}