您的位置:首页 > 产品设计 > UI/UE

IOS给tableview的cell添加长按手势执行两次(UILongPressGestureRecognizer)

2015-04-22 17:35 393 查看
这里我们为tableview添加长按手势

UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(longPressAction:)];
longPressGr.minimumPressDuration =
0.5f;
longPressGr.numberOfTouchesRequired =
1;
[_tableView addGestureRecognizer:longPressGr];
[longPressGr release];

这时我们会发现每次按住tableView并且松开的时候, longPressAction: 这个方法会执行2次

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state ==
UIGestureRecognizerStateBegan) {
CGPoint point = [longPress
locationInView:_tableView];

NSIndexPath *indexPath = [_tableView
indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按

if (indexPath != nil) {
NSLog(@"%ld", indexPath.row);
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐