gpt4 book ai didi

ios - 获取接触点位置

转载 作者:行者123 更新时间:2023-11-28 18:35:45 27 4
gpt4 key购买 nike

我有 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 {


}

最佳答案

UIWebview 包裹在 UIScrollView 中。因此,触摸事件不会传递到您的方法接收触摸事件的 UIView。

对于你的 UIViewController,它应该实现 UIGestureRecognizerDelegate

然后向您的 webview 添加一个手势:

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

下一步:

- (void)tapTest:(UITapGestureRecognizer *)sender {
NSLog(@"%f %f", [sender locationInView:self.yourwebview].x, [sender locationInView:self.yourwebview].y);
}

编辑:

shouldRecognizeSimultaneouslyWithGestureRecognizer 也应该返回 YES。

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

关于ios - 获取接触点位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19564723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com