【问题标题】:Resizing Youtube iFrame while switching iOS device to landscape在将 iOS 设备切换到横向时调整 Youtube iFrame 的大小
【发布时间】:2018-05-27 12:36:45
【问题描述】:

我正在使用 UIWebView 播放 YouTube 视频。它在纵向模式下工作正常。当我切换到横向模式时,Youtube iFrame 不会随着 UIWebView 调整约束而调整大小。有什么办法可以将 Youtube iFrame 更改为横向模式?

【问题讨论】:

标签: ios swift iframe youtube landscape


【解决方案1】:
import UIKit
import WebKit

class ViewController: UIViewController, WKScriptMessageHandler {

    @IBOutlet weak var player: WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
         //palyYoutubePlayer()
        player.configuration.userContentController.add(self, name: "jsHandler")
        let bundleURL = Bundle.main.resourceURL!.absoluteURL
        let html = bundleURL.appendingPathComponent("try.html")
        player.loadFileURL(html, allowingReadAccessTo:bundleURL)
    }

    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if message.name == "jsHandler" {
            print(message.body)
            guard  let event = message.body as? NSString else {
                return
            }
            let str = String(event)
            if str == "reload" {
                self.player.reloadInputViews()
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-08-29
    • 2013-10-15
    • 1970-01-01
    • 2020-12-27
    • 2021-07-14
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多