Uiview 滚动与 webview [英] Uiview scroll with webview

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

问题描述

我在 WkWebview 中有一个网页,在网页中有一个 rect 区域,我想在其中放置一个 UIView 播放直播电影.我已经制作了 webview 和 uiview,但我无法弄清楚如何将 uiview 的位置设置为 rect 区域.也就是说,当用户滚动 webview 时,uiview scroll 也会滚动.uiview 似乎是网页的一部分.如何将 uiview 修复到 webview 中的网页?

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?

感谢您的帮助.

推荐答案

最后我通过使用 javascript 获取网页的注册位置解决了这个问题.然后将 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]
    }
}

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

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