博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITapGestureRecognizer 的用法
阅读量:6252 次
发布时间:2019-06-22

本文共 2278 字,大约阅读时间需要 7 分钟。

//单指单击

2: UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self

3: action:@selector(handleSingleFingerEvent:)];

4: singleFingerOne.numberOfTouchesRequired = 1; //手指数

5: singleFingerOne.numberOfTapsRequired = 1; //tap次数

6: singleFingerOne.delegate = self;

7:

8: //单指双击

9: UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self

10: action:@selector(handleSingleFingerEvent:)];

11: singleFingerTwo.numberOfTouchesRequired = 1;

12: singleFingerTwo.numberOfTapsRequired = 2;

13: singleFingerTwo.delegate = self;

14:

15: //双指单击

16: UITapGestureRecognizer *doubleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self

17: action:@selector(handleDoubleFingerEvent:)];

18: doubleFingerOne.numberOfTouchesRequired = 2;

19: doubleFingerOne.numberOfTapsRequired = 1;

20: doubleFingerOne.delegate = self;

21:

22: UITapGestureRecognizer *doubleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self

23: action:@selector(handleDoubleFingerEvent:)];

24: doubleFingerTwo.numberOfTouchesRequired = 2;

25: doubleFingerTwo.numberOfTapsRequired = 2;

26: doubleFingerTwo.delegate = self;

27:

28: //如果不加下面的话,当单指双击时,会先调用单指单击中的处理,再调用单指双击中的处理

29: [singleFingerOne requireGestureRecognizerToFail:singleFingerTwo];

30: //同理双指亦是如此

31: [doubleFingerOne requireGestureRecognizerToFail:doubleFingerTwo];

32:

33: [self.view addGestureRecognizer:singleFingerOne];

34: [self.view addGestureRecognizer:singleFingerTwo];

35: [self.view addGestureRecognizer:doubleFingerOne];

36: [self.view addGestureRecognizer:doubleFingerTwo];

37:

38: [singleFingerOne release];

39: [singleFingerTwo release];

40: [doubleFingerOne release];

41: [doubleFingerTwo release];

处理事件的方法,代码:

1: //处理单指事件

2: - (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender

3: {

4: if (sender.numberOfTapsRequired == 1) {

5: //单指单击

: NSLog(@"单指单击");

7: }else if(sender.numberOfTapsRequired == 2){

8: //单指双击

9: NSLog(@"单指双击");

10: }

: }

12: //处理双指事件

13: - (void)handleDoubleFingerEvent:(UITapGestureRecognizer *)sender

14: {

15: if (sender.numberOfTapsRequired == 1) {

16: //双指单击

17: NSLog(@"双指单击");

18: }else if(sender.numberOfTapsRequired == 2){

19: //双指双击

20: NSLog(@"双指双击");

21: }

22: }

转载于:https://www.cnblogs.com/daijiahong/p/4432653.html

你可能感兴趣的文章
登陆木星,踏出你的一小步,成就未来一大步
查看>>
都是trigger惹的祸
查看>>
初识Scrapy,在充满爬虫的世界里做一个好公民
查看>>
基于Exchange Server Web Service开发协作、应用平台
查看>>
Oracle11g新特性注意事项
查看>>
Cacti+Nagios监控平台完美整合
查看>>
披星“戴”云,百治百效
查看>>
内存真实利用率
查看>>
由bean,及O/R映射文件导出数据库的方法ExportDB()
查看>>
利用Asp.net中的AJAX制作网页上自动选取开始日期及结束日期的用户自定义控件...
查看>>
python httplib post 进行表单提交数据
查看>>
2003加入域提示“用户已存在”
查看>>
Druid.io索引过程分析——时间窗,列存储,LSM树,充分利用内存,concise压缩
查看>>
Win2008 R2 VDI动手实验系列之四:远程桌面连接代理配置
查看>>
IT人的自我导向型学习:学习的4个层次
查看>>
基于Hadoop数据仓库Hive1.2部署及使用
查看>>
利用shell计算find命令查出后的总文件大小
查看>>
性能之外:LSI 6Gb/s SAS RAID渠道先行
查看>>
SCCM2012系列之十二,SCCM2012部署操作系统
查看>>
Docker镜像导致centos-root根分区容量爆满
查看>>