1

编辑:视频是正在使用的应用程序:即它们是设计用于纵向模式播放的教学视频。

我使用这种方法 (NB iPhoneDevSDK.com 目前被 Google 标记为包含恶意软件,所以要小心。我已经上传了相关帖子的屏幕截图)来打开和播放 YouTube 视频(在幕后使用 UIWebView)。

我要展示的视频是纵向录制的(以 320x480 上传),旨在在纵向模式下很好地填满 iPhone 屏幕。但是,YouTube 视频以强制横向模式开始,并且只能通过将手机移动到横向位置然后再返回来将其变为纵向(有时需要执行几次)。

我想知道的是:有没有办法强制 UIWebView 打开默认为纵向模式的视频播放器?

注意我在生成 UIWebView 的 UIWebView 委托上设置了 (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
  • 第一张图片:默认横向播放视频
  • 第二张图片:人像模式旋转几次

默认为横向 在人像模式下旋转几次

4

2 回答 2

4

我最近遇到了同样的问题并使用了这段代码。这可能不是您问题的正确答案,但它以纵向模式播放 YouTube 视频。

NSString *embedHTML = @"<iframe title=\"YouTube video player\" width=\"320\" height=\"460\" scrolling=\"no\" src=\"http://www.youtube.com/embed/%@?modestbranding=1&amp;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]; 
于 2012-01-31T07:50:49.860 回答
1

对于拥有 UIWebView 的任何视图控制器,您可以指定您只想以纵向模式显示该视图控制器中的所有内容。

比如,说:

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

顺便说一句,有一个有用的问题有很多有用的提示: iPhone SDK:方向(横向和纵向视图)

于 2011-11-15T14:33:43.877 回答