您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页iOS oc-让imageView响应点击

iOS oc-让imageView响应点击

来源:华佗小知识

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(长按)。


Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务