【问题标题】:WKWebView not responding to long clickWKWebView 没有响应长按
【发布时间】:2020-02-28 08:51:43
【问题描述】:

我有一个阅读器,我使用UIWebView 显示HTML 内容,类似于kobo 和iBooks

我现在正在转换到 WKWebView,因为似乎 UIWebView 已被弃用。

我面临WKWebView 根本无法识别长触摸手势并且没有显示选择的问题。虽然使用UIWebView 没有显示此问题。

这就是我实现WKWebView的方式:

WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.selectionGranularity = WKSelectionGranularityCharacter;

readWKWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
readWKWebView.contentMode = UIViewContentModeScaleAspectFit;
readWKWebView.scrollView.scrollEnabled = true;
readWKWebView.multipleTouchEnabled = true;

[self.view addSubview:readWKWebView];
readWKWebView.userInteractionEnabled = true;
readWKWebView.contentMode = UIViewContentModeScaleAspectFit;

[readWKWebView loadFileURL:htmlPathURL allowingReadAccessToURL:[NSURL fileURLWithPath:stringOfAllwedPath]];
[readWKWebView loadHTMLString:loadString baseURL:baseURL];

我确实在HTML 中注入了以下css:

html {
    height:730px;
    font-size:24px;
    width:100%;
}

body {
    margin:0px;
    padding:0px;
    width:100%;
}

#viewer {
    width:668px; 
    height:730px;
}

#book {
    width:668px;
    height:730px;
    margin-left:50px;
    margin-right:50px;
    -webkit-column-count:auto;
    -webkit-column-width:668px;
    -webkit-column-gap:100px;
    text-align:right;
}

.h {
    margin-top:220px;
}

知道缺少选择功能的原因是什么吗?

【问题讨论】:

  • 你想用什么长按?电子邮件?或链接?你也可以附上你的HTML页面
  • 对于选择,我需要从 webview 中选择文本以允许突出显示和其他功能

标签: html objective-c select wkwebview long-click


【解决方案1】:

实际上问题不在于选择本身,但似乎 WKWebView 不像 UIWebView 不响应手势,而在它上面有一个层。所以把它放在前面,问题就解决了。

WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.selectionGranularity = WKSelectionGranularityCharacter;

WKWebView *myWkWebview = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
[self.view addSubview: myWkWebview];
[self.view bringSubviewToFront:myWkWebview];

【讨论】:

    猜你喜欢
    • 2021-07-04
    • 2022-11-02
    • 1970-01-01
    • 2019-06-24
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多