码迷,mamicode.com
首页 > 其他好文 > 详细

CollectionView的cell长按事件实现

时间:2020-05-05 10:48:11      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:cto   row   cti   poi   change   objective   table   https   tee   

原生cell没有长按事件,我们需要使用手势识别来绑定CollectionView。创建并绑定CollectionView如下:

 (void)viewDidLoad {
  [super viewDidLoad];
*/
  
  //创建长按手势监听
  UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                             initWithTarget:self
                                             action:@selector(myHandleTableviewCellLongPressed:)];
  longPress.minimumPressDuration = 1.0;
  //将长按手势添加到需要实现长按操作的视图里
  [self.collectionView addGestureRecognizer:longPress];

处理长按事件:

 (void) myHandleTableviewCellLongPressed:(UILongPressGestureRecognizer *)gestureRecognizer {
  
  
  CGPoint pointTouch = [gestureRecognizer locationInView:self.collectionView];
  
  if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    NSLog(@"UIGestureRecognizerStateBegan");
    
    NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:pointTouch];
    if (indexPath == nil) {
      NSLog(@"");
    }else{
      
      NSLog(@"Section = %ld,Row = %ld",(long)indexPath.section,(long)indexPath.row);
      
    }
  }
  if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
    NSLog(@"UIGestureRecognizerStateChanged");
  }
  
  if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
    NSLog(@"UIGestureRecognizerStateEnded");
  }
}

原文: https://blog.csdn.net/CHENYUFENG1991/article/details/50037361

 

CollectionView的cell长按事件实现

标签:cto   row   cti   poi   change   objective   table   https   tee   

原文地址:https://www.cnblogs.com/modentime/p/12829504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!