Ios 获取接触点位置

Ios 获取接触点位置,ios,uiwebview,touch,Ios,Uiwebview,Touch,我有UIWebView来显示文章。我有用于显示HTML文章的UIWebView。当用户触摸UIWebView中的某个区域时,将显示UIMenuController。然后用户选择注释按钮,显示UITextView。如何获得联系位置 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; // Get the specific p

我有UIWebView来显示文章。我有用于显示HTML文章的UIWebView。当用户触摸UIWebView中的某个区域时,将显示UIMenuController。然后用户选择注释按钮,显示UITextView。如何获得联系位置

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

    // Get the specific point that was touched
    CGPoint point = [touch locationInView:wbCont];
    NSLog(@"X location: %f", point.x);
    NSLog(@"Y Location: %f",point.y);

}


- (void)note:(id)sender  {


}
试试这个:-

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

    NSLog(@" CHECKING CGPOINT %@", NSStringFromCGPoint(firstTouch));


}
对我来说很好;-)

试试这个:-

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

    NSLog(@" CHECKING CGPOINT %@", NSStringFromCGPoint(firstTouch));


}

对我来说很好;-)

只有一种真正的故障安全方法可以做到这一点(据我所知):


Web视图极其复杂,因此覆盖那些
UIResponder
方法或添加手势识别器将不起作用。不幸的是,
hitTest:withEvent:
在每次触摸时都会被调用3次,因此您必须处理这个问题。

只有一种真正的故障安全方法可以做到这一点(据我所知):

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

 UITouch *touch = [touches anyObject];   
    NSLog(@"X location: %f",touch.view.position.x);
    NSLog(@"Y Location: %f",touch.position.y);
}

Web视图极其复杂,因此覆盖那些
UIResponder
方法或添加手势识别器将不起作用。不幸的是,
hitTest:withEvent:
在每次触摸时都会被调用3次,因此您必须处理这个问题。

UIWebview被包装在UIScrollView中。因此,触摸事件不会进入您的方法接收触摸事件的UIView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

 UITouch *touch = [touches anyObject];   
    NSLog(@"X location: %f",touch.view.position.x);
    NSLog(@"Y Location: %f",touch.position.y);
}
对于UIViewController,它应该实现UIGestureRecognitzerDelegate

然后在您的网络视图中添加一个手势:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTest:)];
[tap setDelegate:self];
[self.yourwebview.scrollView addGestureRecognizer:tap]; 
下一步:

编辑:

应使用手势同时识别识别识别器也应返回YES

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

UIWebview被包装在UIScrollView中。因此,触摸事件不会进入您的方法接收触摸事件的UIView

对于UIViewController,它应该实现UIGestureRecognitzerDelegate

然后在您的网络视图中添加一个手势:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTest:)];
[tap setDelegate:self];
[self.yourwebview.scrollView addGestureRecognizer:tap]; 
下一步:

编辑:

应使用手势同时识别识别识别器也应返回YES

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

你发布的代码无效?是的。它没有在nslogIs中显示任何在模拟器中工作的内容?您发布的代码不工作?是的。它在nslogIs Touchs中没有显示任何在模拟器中工作的内容?是的,没有在设备上测试过。是的,尚未在设备上进行测试。@user2807197:请确保use已在.h文件中包含UIgestureRecognitizerDelegate,并且firsttouch更像cgpoint firsttouch。这对我来说很好。轻微更正:将代码更改为-->cgpoint firsttouch=[touch locationInView:self.view]@user2807197:确保use已在.h文件中包含UIgestureRecognitizerDelegate,并且firsttouch更像cgpoint firsttouch。这对我来说很好。次要更正:将代码更改为-->cgpoint firsttouch=[touch locationInView:self.view];如何保存此坐标并稍后获取?如何保存此坐标并稍后获取?