0

我有一个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];

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

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;
}

知道没有选择功能背后的原因是什么吗?

4

1 回答 1

0

事实上,问题不在于选择本身,但似乎 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];
于 2020-06-23T09:10:09.017 回答