我的应用程序仅支持纵向,但我有 WebView ,可以在其中显示 YouTube 视频,并且当该视频全屏播放时,我希望播放器能够进入横向。如何仅支持视频横向?
此外,我还使用外观 API 来设置整个应用程序中导航栏和栏按钮项的样式。这也适用于电影播放器。如何使用电影播放器的默认布局,同时仍在应用程序的其他部分使用外观 API?
最佳答案
我已经成功解决了这两个问题。
对于旋转,请在目标摘要中启用横向方向。
然后将以下行添加到您的 View Controller 中。将其添加到最顶层的 Controller 应该就足够了。例如,如果您的整个应用程序在导航 Controller 中运行,您可以对导航 Controller 进行子类化。
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
从技术上讲,我认为只要让 shouldAutorotate
返回 NO
就足够了,因为它不会在 iOS 6 上旋转,而且如果你不实现 shouldAutorotateToInterfaceOrientation:
我相信它在 iOS 5 中默认为上述内容。无论如何我喜欢包含它。
这将确保您的应用仅在纵向模式下运行,但这不会对 MPAVController(UIWebView 用于在其中呈现视频)产生任何影响,因此它将正确旋转。
为了避免在 MPAVController 上设置外观,我更改了对外观 API 的调用,例如:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"MyBackgroundImage.png"] forBarMetrics:UIBarMetricsDefault];
至
[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil] setBackgroundImage:[UIImage imageNamed:@"NavigationBar_Background.png"] forBarMetrics:UIBarMetricsDefault];
因此,只有当导航栏包含在导航 Controller 中(而不是 MPAVController 中)时,才会设置背景。
关于iphone - UIWebView 中电影播放器的旋转和外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13980785/