编辑:视频是正在使用的应用程序:即它们是旨在以纵向模式播放的教学视频。
我用了this method (NB iPhoneDevSDK.com 目前被谷歌标记为包含恶意软件,所以要小心。我上传了一个 screengrab of the relevant post )打开和播放 YouTube 视频(在幕后使用 UIWebView)。
我想展示的视频是纵向录制的(以 320x480 上传),旨在在纵向模式下很好地填满 iPhone 屏幕。但是,YouTube 视频以强制横向模式开始,并且只能通过将手机移动到横向位置然后再返回来将其变为纵向(有时需要执行几次)。
我想知道的是:有没有办法强制 UIWebView 打开默认为纵向模式的视频播放器?
注意我在生成 UIWebView 的 UIWebView 委托(delegate)上设置了 (interfaceOrientation == UIInterfaceOrientationPortrait)。
编辑:我什至尝试将 UIWebView 子类化,以防止它工作:
@interface AltWebView : UIWebView
@end
@implementation AltWebView
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
最佳答案
我最近遇到了同样的问题并使用了这段代码。
这可能不是您问题的正确答案,但它以纵向模式播放 YouTube 视频。
NSString *embedHTML = @"<iframe title=\"YouTube video player\" width=\"320\" height=\"460\" scrolling=\"no\" src=\"http://www.youtube.com/embed/%@?modestbranding=1&rel=0;autoplay=1;showinfo=0;loop=1;autohide=1\" frameborder=\"0\" allowfullscreen allowTransparency=\"true\"></iframe>";
NSString *htmlStr = [NSString stringWithFormat:embedHTML, videoID]; // videoID is like EgXdUs9HsrQ...
[webView loadHTMLString:htmlStr baseURL:nil];
关于objective-c - 在 UIWebView 中播放 YouTube 视频时强制使用纵向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8137877/