我使用以下代码在iOS中显示youtube视频。
//要在原生网页浏览中显示嵌入youtube视频的Html字符串
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent; background:none;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed src=\"%@\"\
type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, http,viewRect.size.width, (viewRect.size.height*-1)];
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(viewRect.origin.x , (viewRect.origin.y + viewRect.size.height), viewRect.size.width, (viewRect.size.height*-1))];
videoView.delegate = self;
//Stop Image Move
[videoView.scrollView setScrollEnabled:NO];
[self addSubview:videoView];
[videoView loadHTMLString:html baseURL:nil];
videoView.opaque = NO;
[self bringSubviewToFront:videoView];
我为web视图和embed标签指定了相同的宽度和高度。以前在iOS7中,这段代码运行良好,没有任何问题。但是在iOS8中,youtube视频宽度并没有填满网页视图。如果有人就这个问题提出建议,请给我一个帮助。
提前致谢。