【发布时间】:2014-11-10 18:34:07
【问题描述】:
我面临着我似乎无法理解的问题。
我的这段代码可以在 Xcode 5 和 iOS 7 中完美运行:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
NSString* embedHTML = @"\
<html><head><meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; user-scalable=0;\"/>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: black;\
}\
</style>\
</head><body style=\"margin:0;\">\
<embed id=\"yt\" src=\"https://www.youtube.com/v/M7lc1UVf-VE?hd=1\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, width, height];
[webview loadHTMLString:html baseURL:nil];
[self.view addSubview:webview];
}
当我在 Xcode 6 中为 iOS 8 构建相同的代码时,视频会显示在 webview 中,但是太小了。
谁能解释这里发生了什么以及我如何克服这个问题?
【问题讨论】:
-
一个原因可能是,因为这应该是一个官方应用程序并且您链接到的页面声明:“警告:XCDYouTubeKit 违反了 YouTube 服务条款。”不过还是谢谢。
-
@berliner 除了第三方库之外,您找到解决此问题的方法了吗?
-
@ViruMax 不,不幸的是我没有找到这种行为的解释。我最终使用 iframe 而不是嵌入代码。
-
@berliner 能否告诉我或粘贴您的代码,说明您是如何使用 iFrame 的?
标签: ios xcode uiwebview youtube