I have webview.
Now I want to add a subview to it. I added it using addsubview method.
The view got added, but did not scrolled with webview.
I want my subview to be scrolled with the webview.
How can I do that?
Regards, Akshay.
I have webview.
Now I want to add a subview to it. I added it using addsubview method.
The view got added, but did not scrolled with webview.
I want my subview to be scrolled with the webview.
How can I do that?
Regards, Akshay.
You simply need to add your subview to the UIScrollView
of the UIWebView
like this to have your subview scroll with the webview content:
[webView.scrollView addSubview:youSubView];
scrollView
property was added in iOS 5.0. –
Think In order to do that, you would need to tinker with the internals of UIWebView
and find out it's view hierarchy, so you can add the subview inside the scoller.
It's probably easier to tweak your HTML inside the view, so you can include something similar to your custom view (text or an image) in it.
You can later interact with your "fake view" via Javascript.
Try this, it will work
[[[yourwebview subviews] objectAtIndex:0] addSubview:yoursubview];
Suppose you want your uiview on a region with movie id in the html. Check my post here.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.wk.evaluateJavaScript("var rect = document.getElementById('movie').getBoundingClientRect();[rect.left, rect.top];") {
(result, error) -> Void in
print(result)
self.player.view.frame.origin.x = (result as! Array)[0]
self.player.view.frame.origin.y = (result as! Array)[1]
}
}
© 2022 - 2024 — McMap. All rights reserved.