[英]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.