zoukankan      html  css  js  c++  java
  • UITableViewCell 添加长按手势

    1. UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];   
    2.     lpgr.minimumPressDuration = 1.0; //seconds  设置响应时间  
    3.     lpgr.delegate = self;     
    4.     [mTableView addGestureRecognizer:lpgr]; //启用长按事件  
    5.     [lpgr release];  
    6.   
    7. -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer  //长按响应函数  
    8. {  
    9. CGPoint p = [gestureRecognizer locationInView:mTableView ];  
    10.   
    11. //if(gestureRecognizer.state == UIGestureRecognizerStateBegan)  
    12. //{  
    13. //NSLog(@"UIGestureRecognizerStateBegan");  
    14. //}  
    15. //else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)  
    16. //{  
    17. //NSLog(@"UIGestureRecognizerStateEnded");  
    18. //}  
    19. //else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)  
    20. //{  
    21. //NSLog(@"UIGestureRecognizerStateChanged");  
    22. //}  
    23. //else if(gestureRecognizer.state == UIGestureRecognizerStateCancelled)  
    24. //{  
    25. //NSLog(@"UIGestureRecognizerStateCancelled");  
    26. //}  
    27. //else if(gestureRecognizer.state ==UIGestureRecognizerStateFailed )  
    28. //{  
    29. //NSLog(@"UIGestureRecognizerStateFailed");  
    30. //}  
    31.   
    32.   
    33. NSIndexPath *indexPath = [mTableview indexPathForRowAtPoint:p];//获取响应的长按的indexpath  
    34. if (indexPath == nil)  
    35. NSLog(@"long press on table view but not on a row");  
    36. else  
    37. NSLog(@"long press on table view at row %d", indexPath.row);  
    38.   
    39. }  
  • 相关阅读:
    一个支持asp.net2.0和Sql server及Access的免费空间
    ASP.NET2.0数据指南中文版索引
    所阅读的ASP.NET 2.0文章
    SQL SERVER实用技巧
    2000/XP/2003常见问题集锦
    解讀多重啟動引導文件——BOOT.INI
    【译】Html5游戏开发示例(2)
    unity3d 鼠标事件穿透GUI的处理
    【译】Html5游戏开发示例(3)
    unity3d 截屏
  • 原文地址:https://www.cnblogs.com/CodingMann/p/4949178.html
Copyright © 2011-2022 走看看