iOS长按手势UILongPressGestureRecognizer

来源:互联网 发布:seo分析 编辑:程序博客网 时间:2024/06/17 18:03

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

长按手势类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.  }  
1 0
原创粉丝点击