首页 > 移动平台 > 详细

iOS 【手势获取cell位置】【点击cell获取indexpath】

时间:2017-05-09 16:39:13      阅读:483      评论:0      收藏:0      [点我收藏+]

如何获取手指点击的cell位置:

1,首先创建一个长按(可以是点击或者其他手势)

UILongPressGestureRecognizer * longgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]

2,在方法中进行实现

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer

{

//假如是开始点击

if (recognizer.state == UIGestureRecognizerStateBegan )

  {  //获取当前点击的indexpath

    CGPoint location = [recognizer locationInView:self.tableView];

          NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];

    //根据index算出rect

    CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:cellIndexPath];

    CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];

    //这里的rectInSuperview就是你当前手指所点的cell的位置

  }

}

iOS 【手势获取cell位置】【点击cell获取indexpath】

原文:http://www.cnblogs.com/OC888/p/6831211.html

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