---
title: "给UIImageView加手势"
author: "yourgame"
date: "2012-01-10T00:41:35Z"
tags: []
categories: ["移动开发"]
slug: "uiimageview"
draft: false
lastmod: "2012-01-10T00:41:35Z"
id: 1339108
url: "https://yourgame.iteye.com/blog/1339108"
---

默认情况下UIImageView是不支持事件的，要想给他加事件比较麻烦，通过在类中定义下面的方法就可以方便的位UIImageView加事件 imageTaped方法会被调用，在方法中做要处理的内容。

```java
- (void) addGestureRecognizer:(UIImageView *)imageView{
    UITapGestureRecognizer *singleTap = [[[uitapgesturerecognizer alloc] 
                                         initWithTarget:self action:@selector(imageTaped:)]autorelease];
    [imageview addgesturerecognizer:singletap];
}
```