Gir*_*ish 11 javascript iphone uiwebview ios
我有简单UIWebView的加载html文件.我想显示PopOverController指向所选文本的像 -
.
我想要coordinates选择的文字UIWebView.如果我将scalesPageToFit属性设置UIWebView为NO,则此链接正常工作.如果我将scalesPageToFit属性设置UIWebView为YES,则失败.
有人请帮我解决我的问题.
首先删除本机长按手势识别器,如下所示:
for(UIGestureRecognizer *gesRecog in yourWebView.gestureRecognizers)
{
if([gesRecog isKindOfClass:[UILongPressGestureRecognizer class]])
{
[startTF removeGestureRecognizer:gesRecog];
}
}
Run Code Online (Sandbox Code Playgroud)
然后指定一个自定义的:
UILongPressGestureRecognizer *myOwnLongPressRecog = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleWebViewLongpress:)];
// set numberOfTapsRequired and numberOfTouchesRequired as per your requirement:
[yourWebView addGestureRecognizer:myOwnLongPressRecog];
Run Code Online (Sandbox Code Playgroud)
// 像这样处理长按:
- (void) handleWebViewLongpress: (UIGestureRecognizer *) recog
{
int zoomedWidth = [[yourWebView stringByEvaluatingJavaScriptFromString:@"window.innerWidth"] intValue];
CGFloat scale = yourWebView.frame.size.width / zoomedWidth; // get the scaled value of your web view
CGPoint zoomedCords = [gesture locationInView:self.webView];
zoomedCords.x /= scale; // Normal math. Divide by the scale to get the real thing.
zoomedCords.y /= scale;
NSLog(@"%@", zoomedCords);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2310 次 |
| 最近记录: |