当有人在应用程序的任何部分点击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方法使用错误.
这是我对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>>
谢谢!
解决方法 我想你可以说[event touchesForVIEw:< image vIEw>].如果返回空数组,则关闭图像视图.在表视图控制器的touchesBegan:withEvent:中执行此 *** 作,并确保调用[super touchesBegan:touches withEvent:event],否则您的表视图将完全停止工作.你可能甚至不需要实现touchesEnded:/ Cancelled:…,或touchesMoved:….在这种情况下,UITapGestureRecognizer看起来似乎有些过分.
总结以上是内存溢出为你收集整理的ios – 如何检测在UIImageView外部点击的人全部内容,希望文章能够帮你解决ios – 如何检测在UIImageView外部点击的人所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)