UIImageView继承UIVIew
可以使用UIVIew的addGestureRecognizer方法
... ...
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTapAction)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
... ...
另外还需要添加 [imageView setUserInteractionEnabled:YES];
-(void)singleTapAction
{
// 这里添加点击后要做的事情
}
不止可以为imageview添加手势,也可以为view添加
好了 其实主要就是要会使用UITapGestureRecognizer,当然这只是手势的其中一个。下面还有几个如:
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer
从命名上不难了解這些类別所对应代表的手势,分別是 Tap(点一下)、Pinch(二指往內或往外拨动)、Rotation(旋转)、Swipe(滑动,快速移动)、Pan (拖移,慢速移动)以及 LongPress(长按)。