UITableView长按手势UILongPressGestureRecognizer

移动开发 iOS
给UITableView 添加长按手势,识别长按哪一行,按手势类UILongPressGestureRecognizer,属minimumPressDuration表示最短长按的时间.

给UITableView 添加长按手势,识别长按哪一行。

长按手势类UILongPressGestureRecognizer, 属性minimumPressDuration表示最短长按的时间

添加手势代码:

  1. UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];   
  2.      longPressGr.minimumPressDuration = 1.0;   
  3.      [self.tableView addGestureRecognizer:longPressGr];   
  4.     [longPressGr release];  

响应长按事件代码:

  1. -(void)longPressToDo:(UILongPressGestureRecognizer *)gesture   
  2.  {   
  3.      if(gesture.state == UIGestureRecognizerStateBegan)   
  4.      {   
  5.          CGPoint point = [gesture locationInView:self.tableView];   
  6.         NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];   
  7.          if(indexPath == nil) return ;   
  8.         //add your code here   
  9.     }   
  10.  }  
责任编辑:闫佳明 来源: oschina
相关推荐

2014-12-31 16:48:43

Touch touchevent多点触摸

2015-07-22 10:34:59

手势密码源码

2011-07-07 16:38:21

iOS UITableVie

2013-06-20 11:21:58

iOS开发UITableView

2011-08-02 17:14:41

iPhone应用 UITableVie

2013-05-14 11:18:24

AIR AndroidSwipe手势

2021-05-20 09:00:27

SwiftUI Swift TapGesture

2022-05-17 12:25:59

物联网智能建筑楼宇自控

2011-07-27 11:19:33

iPhone UITableVie

2011-07-27 11:14:37

iPhone UITableVie

2013-05-14 11:16:26

AIR Android旋转手势

2013-06-20 10:50:51

Objective-CiOS左右滑动手势

2013-12-08 22:02:24

手势交互交互设计交互体验

2011-08-15 13:44:07

iPhone开发UITableView

2013-07-25 14:12:53

iOS开发学习UITableView

2012-04-04 22:36:52

iOS5

2013-07-18 18:06:53

UITableview

2010-11-01 09:46:21

ViewAndroid

2013-05-07 17:21:09

ELMOS芯片手势识别

2021-10-19 08:33:10

Android手势检测
点赞
收藏

51CTO技术栈公众号