【问题标题】:Rotation and appearance of movie player in UIWebViewUIWebView中电影播放器​​的旋转和外观
【发布时间】:2012-12-20 21:30:32
【问题描述】:

我的应用程序仅支持纵向,但我有显示 YouTube 视频的 Web 视图,当该视频全屏播放时,我希望播放器能够进入横向。如何仅支持视频的横向?

另外,我使用外观 API 来设置整个应用程序中导航栏和栏按钮项的样式。这也适用于电影播放器​​。如何在应用程序的其他部分仍然使用外观 API 的同时使用电影播放器​​的默认布局?

【问题讨论】:

  • 非常感谢您将此标记为cocoa-touch 而不是xcode。你摇滚!

标签: iphone objective-c cocoa-touch uiwebview uiappearance


【解决方案1】:

我已经设法解决了这两个问题。

对于旋转,在目标摘要中启用横向。

然后将以下行添加到您的视图控制器。将其添加到最顶层的控制器就足够了。例如,如果您的整个应用程序在导航控制器中运行,您可以子类化导航控制器。

- (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];

因此,只有当导航栏包含在导航控制器中时才会设置背景,而导航控制器不在 MPAVController 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多