UIImageView繼承UIVIew
可以使用UIVIew的addGestureRecognizer方法
... ...
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self? ? ? ? ? ? ? ? action:@selector(singleTapAction)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
... ...
另外還需要添加 [imageView setUserInteractionEnabled:YES];
-(void)singleTapAction
{
// 這里添加點(diǎn)擊后要做的事情
}
不止可以為imageview添加手勢(shì)榕吼,也可以為view添加
好了? 其實(shí)主要就是要會(huì)使用UITapGestureRecognizer亲族,當(dāng)然這只是手勢(shì)的其中一個(gè)。下面還有幾個(gè)如:
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer
從命名上不難了解這些類(lèi)別所對(duì)應(yīng)代表的手勢(shì),分別是 Tap(點(diǎn)一下)崎溃、Pinch(二指往內(nèi)或往外撥動(dòng))糊啡、Rotation(旋轉(zhuǎn))、Swipe(滑動(dòng)躺彬,快速移動(dòng))伸辟、Pan (拖移麻惶,慢速移動(dòng))以及 LongPress(長(zhǎng)按)。