使用webview的Uiview滚动 [英] Uiview scroll with webview

查看:136
本文介绍了使用webview的Uiview滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WkWebview中有一个网页,并且在网页上有rect区域,我想在其中放置一个UIView播放实况电影。我已经制作了webview和uiview,但我无法弄清楚如何使uiview在rect区域的位置。也就是说,当用户滚动webview时,uiview滚动也滚动。看来uiview是网页的一部分。

I have a webpage in WkWebview, and in the webpage there is rect region where I want to put a UIView playing live movie. I've made the webview and uiview, but I cannot figure out how to make the uiview's position to the rect region. That's to say, when user scroll the webview, the uiview scroll also scrolls. It seems the uiview is a a part of webpage. How can I fix the uiview to webpage in webview?

感谢您的帮助。

Thanks for any help.

推荐答案

最后,我通过使用javascript解决了这个问题,以获取网页的regin位置。然后将UIView设置到该位置。

Finally I solved this by use javascript to get the regin location of webpage. Then set the UIView to that location.

以下是网页中regin div标记电影的代码,uiview具有名称播放器。

Here is the code, in the webpage the regin div has tag movie, and the uiview has name player.

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

这篇关于使用webview的Uiview滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆