UIButton的长按事件 tableview

//button的长按事件

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(btnLong:)];

    //长按时间

    longPress.minimumPressDuration = 0.8;

    [button addGestureRecognizer:longPress];

#pragma mark -
#pragma mark Table Delegate Methods 
- (NSInteger)tableView:(UITableView *)tableView 
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

表格:可以使内容的选择,现实两种动画效果

    cell.imageView.image = image;
    cell.imageView.highlightedImage = image2;

表格:取消选中项的选择动画

 [tableView deselectRowAtIndexPath:indexPath animated:YES];

//添加长按事件
 UILongPressGestureRecognizer *lpr = [[UILongPressGestureRecognizer alloc] 
            initWithTarget:self 
            action:@selector(LongPressEvent:)];
 lpr.minimumPressDuration = 0.8;
 [self addGestureRecognizer:lpr];
 [lpr release];

截取长按事件:

- (void)LongPressEvent:(UILongPressGestureRecognizer  *)gestureRecognizer{
 CGPoint p=[gestureRecognizer locationInView:listenView];
 NSIndexPath *indexpath=[listenView indexPathForRowAtPoint:p];
 if (indexpath==nil) {
  return;
 }
 self.editBookinfo = [filearray objectAtIndex:[indexpath row]];
}

原文地址:https://www.cnblogs.com/Cristen/p/2778801.html