问题描述
我要在iframe
中使用WKWebView
加载Vimeo视频链接,我想要做的就是在顶部添加自定义顶部栏,并带有后退按钮,在底部添加UITextView
的视图。
我试图将顶部栏作为子视图添加到WKWebView
,但似乎不起作用。
如果我们无法将子视图添加到WKWebView
,另一种解决方案是什么?请记住,我需要在loadView()
函数中而不是在viewDidLoad()
中配置Web视图实例,以便能够在Web中而不是全屏显示内联视频。
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlinemediaplayback = true //This works only in loadView function
webView = WKWebView(frame: .zero,configuration: webConfiguration)
webView.uiDelegate = self
webView.backgroundColor = .black
webView.isOpaque = false
webView.scrollView.isScrollEnabled = false
webView.scrollView.bounces = false
view = webView
}
我在loadIframe()
中使用的viewDidLoad()
函数
private func loadIFrame() {
if videoDetails.mVideoUrl.lowercased().contains("vimeo.com") {
guard let url = URL(string: videoDetails.mVideoUrl) else {
print("NOT URL LINK")
return
}
self.view.backgroundColor = .black
let vimeoSeparate = videoDetails.mVideoUrl.components(separatedBy: "/").last
let vimeoNumber = vimeoSeparate?.components(separatedBy: "?").first
print("VIDEO URL: \(url)")
print("NUMBER: \(vimeoNumber!)")
let embedHTML = "<body style=\"margin:0px;padding:0px;overflow:hidden;background-color: black;color: black;\">" + " <iframe style=\"overflow: hidden; overflow-x: hidden; overflow-y:hidden; height: 0;" + " max-height: 100%; max-width: 100%; min-height: 100%;min-width: 100%; width: 0;scrolling:no;position:absolute;top:0px;left:0px;right:0px;bottom:0px\" " + "src=https://player.vimeo.com/video/\(vimeoNumber!)?autoplay=1&title=0&byline=0&portrait=0&sidedock=0&controls=1&playsinline=1\"></iframe>" + "</body>"
print(embedHTML)
webView.contentMode = UIViewContentMode.scaleAspectFit
webView.loadHTMLString(embedHTML as String,baseURL: nil )
}
}
iframe加载成功,但是我看不到在loadIframe()
函数之后也加载的添加的子视图。
private func loadTopNavBar() {
topNavBarView = UIView()
backBtn = UIButton()
topNavBarView.translatesAutoresizingMaskIntoConstraints = false
backBtn.translatesAutoresizingMaskIntoConstraints = false
backBtn.setimage(#imageLiteral(resourceName: "back"),for: .normal)
topNavBarView.backgroundColor = .green
UIUtilities.addTapGesturetoView(backBtn,withTarget: self,andSelector: #selector(back(_:)),andCanCanceltouchesInTheView: false)
topNavBarView.addSubview(view)
backBtn.addSubview(topNavBarView)
topNavBarView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
topNavBarView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
topNavBarView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
topNavBarView.heightAnchor.constraint(equalToConstant: 50).isActive = true
backBtn.leftAnchor.constraint(equalTo: topNavBarView.leftAnchor,constant: 12).isActive = true
backBtn.centerYAnchor.constraint(equalTo: topNavBarView.centerYAnchor).isActive = true
backBtn.heightAnchor.constraint(equalTo: view.heightAnchor,multiplier: 0.05,constant: 0).isActive = true
backBtn.widthAnchor.constraint(equalTo: view.widthAnchor,constant: 0).isActive = true
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)