---
title: "iphone 处理单击和双击Touch"
author: "wanglei0119"
date: "2010-09-24T00:40:10Z"
tags: []
categories: ["移动开发"]
slug: "iphone-touch"
draft: false
lastmod: "2010-09-24T00:40:10Z"
id: 770212
url: "https://wanglei0119.iteye.com/blog/770212"
---

如果以不同的方式响应单击和双击事件时，就会出现复杂的情况。那么如何知道一个单击不是另一个双击的起始部分呢？一下代码可以用来处理处理这种情况：

在你的UIView或UIViewController里重载touchesBegan和touchesEnded方法:

```java
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyobject];
	if ([touch tapcount] == 2) {
        [nsobject cancelpreviousperformrequestswithtarget:self];
    } else {
		[self performselector:@selector(testsingletouch:) withobject:touch afterdelay:0.5f];
	}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyobject];
	if ([touch tapcount] == 2) {
        [self testmultipletouch];
    }
}
```