zoukankan      html  css  js  c++  java
  • iOS 【手势获取cell位置】【点击cell获取indexpath】

    如何获取手指点击的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的位置

      }

    }

  • 相关阅读:
    hdu 5902 Seam Carving
    hdu 5091 Beam Cannon
    hdu 1542 Atlantis
    hdu 2196 Computer
    第一个爬虫和测试
    排球比赛规则
    第十周博客作业
    科学计算可视化
    用matplotlib绘制图像
    面对对象学习
  • 原文地址:https://www.cnblogs.com/OC888/p/6831211.html
Copyright © 2011-2022 走看看