zoukankan      html  css  js  c++  java
  • UITableViewCell 的长按事件处理

    今天做任务的时候遇到了UITableViewCell的长按处理,比如按住一秒之后触发事件。刚开始本想自定义cell,然后在里面捕捉touch事件,touchbegin后开始计时,超过一秒触发事件,不过想想如此有点麻烦,然后查下了orgnizer,发现了

    UILongPressGestureRecognizer这个类,嘿嘿,确实是我需要的,然后查看文档,发现其可以支持多指长按,不过这里我需要单指就可以了。使用方法也比较方便,大家直接参考代码就可以了:

    UILongPressGestureRecognizer *longPressReger = [[UILongPressGestureRecognizer alloc]

    initWithTarget:self action:@selector(handleLongPress:)];

    longPressReger.minimumPressDuration = 1.0;

    [myTableView addGestureRecognizer:longPressReger];

    [longPressReger release];

     

    -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer

    {

    CGPoint point = [gestureRecognizer locationInView:myTableView];

     

    if(gestureRecognizer.state == UIGestureRecognizerStateBegan)

    {

    }

    else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)

    {

    }

    else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)

    {

    }

    NSIndexPath *indexPath = [myTableView indexPathForRowAtPoint:point];

    if (indexPath == nil)

    NSLog(@”not tableView”);

    else

    {

    focusRow = [indexPath row];

    focusView.hidden = NO;

    }

    }

  • 相关阅读:
    centos7物理机a start job is running for dev-mapper-centosx2dhome.device
    jenkins pipeline流水线
    nginx 加载慢 负载均衡不均衡
    山田预发环境发布脚本
    prometheus 监控容器
    maven私服安装使用
    日志清理
    ERROR 1046 (3D000) at line 1: No database selected
    网络工程学习经典书籍推荐
    每日一句
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090546.html
Copyright © 2011-2022 走看看