gpt4 book ai didi

ios - 尝试从 WebView 加载 YouTube 视频时出现约束警告

转载 作者:搜寻专家 更新时间:2023-10-31 19:31:34 24 4
gpt4 key购买 nike

我正在尝试使用 WebView 加载 YouTube 视频。视频播放效果很好,完全符合我的要求,但调试器不断发出警告(见结尾)。此警告重复约 20 次。

我试图隔离问题并创建一个没有任何约束的新 ViewController,它仍然显示与约束相关的警告。

我尝试使用 .translatesAutoresizingMask.scalesToFitPage 但它们似乎没有什么区别。

这是我用来嵌入视频的代码:

// webView from an IBOutlet in an empty ViewController without any constraints

func playVideo(){

var staticUrlString = "https://www.youtube.com/watch?v=jNQXAC9IVRw"
var youtubeVideoId = NSString(string: staticUrlString)
var rng: NSRange = youtubeVideoId.rangeOfString("&feature=")

if(rng.length>0){
youtubeVideoId = youtubeVideoId.stringByReplacingCharactersInRange(NSMakeRange(rng.location, youtubeVideoId.length-rng.location), withString: "")
}

youtubeVideoId = youtubeVideoId.stringByReplacingOccurrencesOfString("http://www.youtube.com/watch?v=", withString: "")
youtubeVideoId = youtubeVideoId.stringByReplacingOccurrencesOfString("https://www.youtube.com/watch?v=", withString: "")

var youTubeVideoHTML: NSString = NSString(format: "<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px; background:#1111}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%@', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } });} function onPlayerReady(event) { event.target.playVideo(); } function onPlayerStateChange(event) {if(event.data === 0) { event.target.destroy(); }} </script> </body> </html>",0.0, 0.0,youtubeVideoId)

//webView.translatesAutoresizingMaskIntoConstraints()
//webView.scalesPageToFit = false
webView.mediaPlaybackRequiresUserAction = false
webView.opaque = false

webView.loadHTMLString(youTubeVideoHTML, baseURL: NSURL(string: NSString(format: "http://www.youtube.com/watch?v=%@", youtubeVideoId)))


println("play")
}

这是警告之一:

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7cb37910 UIImageView:0x7cb36fb0.centerX == AVUnsupportedContentIndicatorView:0x7cb36cf0.centerX>",
"<NSLayoutConstraint:0x7cb37d70 H:[UIImageView:0x7cb36fb0]-(>=10)-| (Names: '|':AVUnsupportedContentIndicatorView:0x7cb36cf0 )>",
"<NSLayoutConstraint:0x7cb4f430 H:|-(0)-[AVUnsupportedContentIndicatorView:0x7cb36cf0] (Names: '|':UIView:0x7cb36b20 )>",
"<NSLayoutConstraint:0x7cb4f460 H:[AVUnsupportedContentIndicatorView:0x7cb36cf0]-(0)-| (Names: '|':UIView:0x7cb36b20 )>",
"<NSLayoutConstraint:0x7cb4f310 H:|-(0)-[UIView:0x7cb36b20] (Names: '|':AVPlayerView:0x7cb36860 )>",
"<NSLayoutConstraint:0x7cb4f360 H:[UIView:0x7cb36b20]-(0)-| (Names: '|':AVPlayerView:0x7cb36860 )>",
"<NSLayoutConstraint:0x7cb5ef40 'UIView-Encapsulated-Layout-Width' H:[AVPlayerView:0x7cb36860(1)]>"
)


Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7d342240 UIView:0x7d229b90.centerX == AVExternalPlaybackIndicatorView:0x7d22a150.centerX>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

最佳答案

您收到警告的约束似乎与您直接创建的 View 无关——它们与 Apple 的内部 View 结构有关。

这(很可能)是一个错误。您应该在此处提交报告:https://bugreport.apple.com .

关于ios - 尝试从 WebView 加载 YouTube 视频时出现约束警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26632201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com