在 UIWebView 中播放 YouTube 视频时强制纵向模式
编辑:这些视频是正在使用的应用程序的视频:即它们是设计为以纵向模式播放的教学视频。
我使用了这种方法 (注意 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
- 第一张图片:默认情况下以横向方式播放视频
- 第二张图片:纵向模式旋转了几次
edit: The videos are of the app being used: i.e. they're instructional videos designed to be played in portrait mode.
I used this method (NB iPhoneDevSDK.com is currently marked by Google as containing malware, so be careful. I've uploaded a screengrab of the relevant post) to open & play a YouTube video (using a UIWebView behind the scenes).
The video I want to show was recorded in portrait (uploaded in 320x480) and was intended to fill the iPhone screen nicely when in portrait mode. However, the YouTube video starts in a forced landscape mode, and can only be put into portrait by moving the phone to a landscape position and then back again (sometimes needs to be done a few times).
What I'm wondering is: is there a way of forcing the UIWebView to open a video player that defaults to portrait mode?
NB I've set (interfaceOrientation == UIInterfaceOrientationPortrait) on the UIWebView delegate that's spawning the UIWebView.
Edit: I even tried subclassing UIWebView on the off-chance that this would get it to work:
@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
- First image: video playing in Landscape by default
- Second image: Portrait mode once rotated a few times
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近遇到了同样的问题并使用了这段代码。
这可能不是您问题的正确答案,但它会以纵向模式播放 YouTube 视频。
I've been facing same problem recently and used this code.
This may not be the right answer to your question but it plays YouTube video in portrait mode.
对于拥有 UIWebView 的任何视图控制器,您可以指定只想以纵向模式显示该视图控制器中的所有内容。
顺便说一句,
有
一个有用的问题,其中有很多有用的提示: iPhone SDK:方向(横向和纵向视图)
For whichever view controller that owns the UIWebView, you could specify that you only want to display everything from that view controller in portrait mode.
Something like, say:
and
B.T.W., there's a helpful question with lots of helpful hints over at: iPhone SDK: Orientation (Landscape and Portrait views)