单击“直接查看”时,ios locationInView未显示正确的日志
我觉得很奇怪,我有黑暗的视野和绿色的视野 我使用单击“直接查看”时,ios locationInView未显示正确的日志,ios,objective-c,Ios,Objective C,我觉得很奇怪,我有黑暗的视野和绿色的视野 我使用 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint touchViewPoint = [touch locationInView:touch.view]; NSLog(@"[self.darkScreenView p
-(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]);
}
当我单击暗视图或绿色视图时
日志仍然显示1。为什么?
我点击绿色视图应该显示日志0,但我仍然得到日志结果1
我使用的是xcode 6.3.1
有人知道在这种情况下有什么问题吗
谢谢~尝试联系不同的观点
-(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
}
}
触摸视点的位置相对于触摸视图。因此,获取相对于self.darkView的位置,如下所示
CGPoint touchViewPoint = [touch locationInView: self.darkView];
以下是您所指视图的问题更改
-(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]);
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint touchViewPoint=[touch locationInView:darkView];这将起作用
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]);
你的问题:
touch视点
相对于touch.view
坐标
您必须首先将点转换为暗视图坐标,然后您可以使用pointInside:pointOfDarkView
您共享的代码,处理暗视图和绿色视图的两种情况?您能记录CGPoint结果吗?谢谢您的回答。谢谢您的回答。我使用@文昌黄回答解决问题。:p