Uiview scroll with webview

后端 未结 2 829
野性不改
野性不改 2020-12-11 14:05

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 figur

相关标签:
2条回答
  • 2020-12-11 14:30

    For this can you go to storyboard and see if the uiview is inside the view or not and if then drag it outside and try to set its frame in property console because if you drag and drop to set uiview frame it will be gone in subview of your uiwebview

    Hope it will help you

    0 讨论(0)
  • 2020-12-11 14:40

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

    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]
        }
    }
    
    0 讨论(0)
提交回复
热议问题