coder
coder

Reputation: 5400

WKWebView not responding to long click

I have a reader on which I was using UIWebView to display HTML content, similar to the kobo and iBooks.

I am transitioning now to WKWebView as it seems that UIWebView is deprecated.

I am facing the problem that WKWebView doesn't recognize at all the long touch gesture and no selection is showing. While this problem didn't show using the UIWebView.

This is how I'm implementing 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];

I do inject the following css in the 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;
}

Any idea what could be the reason behind absence of selection feature?

Upvotes: 0

Views: 230

Answers (1)

coder
coder

Reputation: 5400

In fact the problem wasn't with the selection itself, but seems that WKWebView unlike UIWebView does not respond to gesture while having a layer on top of it. so on bringing it to front the problem was resolved.

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

Upvotes: 0

Related Questions