首页 > 移动平台 > 详细

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

时间:2015-04-22 18:09:09      阅读:365      评论:0      收藏:0      [点我收藏+]

这里我们为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);

        }

        

    }

}



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

原文:http://blog.csdn.net/s133315202/article/details/45198083

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!