Reputation: 7068
I have a web page for testing purposes (https://storage.googleapis.com/htmltestingbucket/nested_scroll_helper.html) that just prints a counter of the scroll event the html has caught in a fixed header
When the WKWebView is the only scroll-able element in the fragment everything is fine and the WebView sends the scroll events to the page
If I want to add native elements above and below the WebView then things get much more complex.
UIScrollView
UILabel
WKWebView
UILabel
I know it's not good to have a WebView inside a ScrollView but I have to provide a single scrolling experience with hybrid content and proper scrolling events in the html document. I found plenty of questions on the matter but I was not able to create a full end-to-end solution.
Upvotes: 11
Views: 4698
Reputation: 5776
Update: Okay took me a while to understand what you're trying to do.
I know you would like to keep the outer scrollView, but I'm pretty sure it's not possible to achieve what you want to do (only way could be if you set the outerScrollView.delegate = webView
- but didn't work for me when I tried)
I think the best solution would be:
webView.contentInset = UIEdgeInsetsMake(100,0,100,0);
Previously (Other way around):
webView.scrollView.scrollEnabled = NO;
in your viewDidLoad
or the storyboardwebView.scrollView.contentSize.height
s content height via
self.webViewContentHeightConstraint.constant = webView.scrollView.contentSize.height
Don`t forget to do steps 4 & 5 whenever the webView did finish loading content
Upvotes: 5
Reputation: 3231
You basically have a scrollview inside a scrollview. How do you suppose that would work? I would add the labels to the HTML in the WebView. Don't see any reason why they need to be native.
Alternatively, you could try to add the labels to the UIWebView's UIScrollView. That's it's first subview. Not sure if you need to adjust the scrollview insets. Injecting html probably would work more reliably.
Upvotes: 0