简体   繁体   English

当我单击直接查看时,ios locationInView无法显示正确的日志

[英]ios locationInView not show correct log when I click direct view

I feel strange, I have dark view(darkScreenView) and green view. 我感到很奇怪,我有暗视图(darkScreenView)和绿视图。

I using the 我用

 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
     UITouch *touch = [[event allTouches] anyObject];
     CGPoint touchViewPoint = [touch locationInView:touch.view];

      NSLog(@"[self.darkScreenView pointInside:touchViewPoint withEvent:event]:%d",[self.darkView pointInside:touchViewPoint withEvent:event]);
 }

When I click on the dark view or green view, 当我单击深色视图或绿色视图时,

The Log still show 1. why? 日志仍然显示1.为什么?

I click on the green view should show log 0, but I still get the log result 1. 我单击绿色视图时应显示日志0,但我仍然得到日志结果1。

在此处输入图片说明

在此处输入图片说明

I am using xcode 6.3.1. 我正在使用xcode 6.3.1。

Have anyone know what problem in this situation? 有谁知道在这种情况下有什么问题吗?

Thank you~ 谢谢〜

Try to get touch for different views.. 尝试接触不同的观点。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
  UITouch *touch = [[event allTouches] anyObject];
  if (touch.view==GREEN_VIEW)
  {
    //Write your code for green view here
  }
  else if(touch.view==DARK_VIEW)
  {
    //Write your code for dark view here
  }
}

Your touchViewPoint's location is relative to the touched view. 您的touchViewPoint的位置是相对于触摸视图的。 So get location relative to self.darkView like below. 因此,获取相对于self.darkView的位置,如下所示。

CGPoint touchViewPoint = [touch locationInView: self.darkView];

Here is the problem change to View you are referring to. 这是您要引用的View的问题更改。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
     UITouch *touch = [[event allTouches] anyObject];
     CGPoint touchViewPoint = [touch locationInView:darkView];   <----- Problem

      NSLog(@"[self.darkScreenView pointInside:touchViewPoint withEvent:event]:%d",[self.darkView pointInside:touchViewPoint withEvent:event]);
 }

This will work 这会起作用

UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchViewPoint = [touch locationInView:touch.view];
    CGPoint  pointOfDarkView = [touch.view convertPoint:touchViewPoint toView:self.darkview];
    NSLog(@"[self.darkScreenView pointInside:touchViewPoint withEvent:event]:%d",[self.darkview pointInside:pointOfDarkView withEvent:event]);

Your problem: 你的问题:

touchViewPoint is relative to touch.view coordinate touchViewPoint相对于touch.view坐标

You have to convert point to darkview coordinate first,then you can use pointInside:pointOfDarkView 您必须先将点转换为Darkview坐标 ,然后才能使用pointInside:pointOfDarkView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击IOS中的按钮时,为什么视图不显示? - Why the view doesn't show when I click the button in IOS? 当我使用子视图调用父视图时,iOS UIPageControl无法显示正确的页码 - iOS UIPageControl not show correct pages number when I using subview call parent view 当我在iOS中点击google上的标记时,如何使用两个按钮显示叠加信息视图 - How to show overlay info view with two button more when i click a marker on google in iOS 调用locationInView时出错: - Error when calling locationInView: 使用触摸事件的locationInView时,如何确定设备上CGPoint的有效范围? - How do I determine what the valid range is for CGPoint on a device when using locationInView of touch events? 单击链接时显示警报视图 - Show alert view when click on a link 为什么我再次隐藏并显示时,iOS工具栏视图会添加到加载视图的顶部? - Why does the iOS toolbar view get added on top of my loading view when I hide and show it again? iOS-手机锁定时显示视图 - iOS - Show View when phone is locked 单击下一个视图控制器的按钮时,如何显示加载标签? - How can I get my loading label to show up when I click button to next view controller? IOS:应用启动时显示视图 - IOS: show a view when an app start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM