WebView嵌入了youtube视频位置

时间:2016-10-24 01:55:39

标签: swift webview

EXAMPLE HERE!!!

   override func viewDidLoad() {
        super.viewDidLoad()
            secondVideoPlayer.allowsInlineMediaPlayback = true
            secondVideoPlayer.loadHTMLString("<iframe width=\"\(newVideoPlayer.frame.width)\" height=\"\(newVideoPlayer.frame.height)\" src=\"\(urlString)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>",baseURL: nil)
    }

Youtube视频位置启动不正确,要正确看到我总是要拖动它我该如何解决?如何手动设置他的起始位置?

1 个答案:

答案 0 :(得分:2)

iframe包裹在body内并将marginpadding设置为零,因此内容从左上角开始。

secondVideoPlayer.loadHTMLString("<body style=\"margin: 0; padding: 0;\"><iframe width=\"\(newVideoPlayer.frame.width)\" height=\"\(newVideoPlayer.frame.height)\" src=\"\(urlString)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe></body>",baseURL: nil)