大佬教程收集整理的这篇文章主要介绍了ios – 如何检测在UIImageView外部点击的人,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当有人在应用程序的任何部分点击UIImageView之外时,我希望UIImageView能够消失.
@interface SomeMasterViewController : UITableViewController <clip> <clip> @property (strong,nonatomiC) UIImageView *someImageView;
stackoverflow和apple的文档中有一些提示听起来像我需要的.
> Apple’s : Gesture Recognizers
> Apple’s : UIView hitTest:withEvent
> Apple’s : UITouch Class Reference
> Stackoverflow: Listening to UITouch event along with UIGestureRecognizer
> (not likely needed but..) – CGRectContainsPoint as mentioned in the following post titled: Comparing a UITouch location to UIImageView rectangle
>注册UITapGestureRecognizer以获取应用程序中可能发生的所有触摸事件
> UITapGestureRecognizer应该有cancelsTouchesInView和
delaysTouchesBegan和delaysTouchesEnded设置为NO.
>将这些触摸事件与someImageView进行比较(如何使用UIView hitTest:withEvent?)
更新:我正在使用主UIWindow注册UITapGestureRecognizer.
最终未解决的部分
我有一个UTapGestureRecognizer将调用的handleTap:(UITapGestureRecognizer *).如何获取给定的UITapGestureRecognizer并查看水龙头是否落在UIImageView之外?识别器的LOCATIOnInView看起来很有希望,但我没有得到我期望的结果.当我点击它时我希望看到某个UIImageView,当我点击另一个点时看不到UIImageView.我觉得LOCATIOnInView方法使用错误.
- (void)handleTap:(UITapGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateEnded) { NSLog(@"handleTap NOT given UIGestureRecognizerStateEnded so nothing more to do"); return; } UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window]; CGPoint point = [gestureRecognizer LOCATIOnInView:mainWindow]; NSLog(@"point x,y computed as the LOCATIOn in a given view is %f %f",point.x,point.y); UIView *touchedView = [mainWindow hitTest:point withEvent:nil]; NSLog(@"touchedView = %@",touchedView); }
我得到以下输出:
<clip>point x,y computed as the LOCATIOn in a given view is 0.000000 0.000000 <clip>touchedView = <UIWindow: 0x8c4e530; frame = (0 0; 768 1024); opaque = NO; autoresize = RM+BM; layer = <UIWindowLayer: 0x8c4c940>>
谢谢!
以上是大佬教程为你收集整理的ios – 如何检测在UIImageView外部点击的人全部内容,希望文章能够帮你解决ios – 如何检测在UIImageView外部点击的人所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。