25

从 iOS 3.2 开始,MPMoviePlayerController 类允许在视图层次结构中嵌入电影。现在我面临这个问题:我通过放置 MPMoviePlayerController 的实例来创建我的纵向视图。当用户触摸“全屏”按钮时,该视图进入全屏模式,但视图保持纵向。当用户旋转设备时,全屏电影视图不会自动旋转,因为我的应用程序禁止横向界面方向。因此,为了允许电影播放器​​全屏视图自动旋转,我更改了我的视图控制器 shouldAutorotateToInterfaceOrientation: 方法,当且仅当电影播放器​​处于全屏模式时为横向返回 YES。这很完美:当用户全屏输入然后旋转到横向时,播放器会自动旋转到横向并填满整个屏幕。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}

现在,当我在全屏视图中触摸“完成”按钮同时保持横向时,就会出现问题。全屏关闭,然后我看到的是我的原始视图自动旋转:但我不想要这种自动旋转。

一个部分但不可接受的解决方案是侦听“MPMoviePlayerDidExitFullscreenNotification”,如果界面旋转为横向,则强制重新定向以使用未记录的私有函数:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]

这可行,但不可接受,因为禁止使用此方法。

我尝试使用强制定向,[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]但由于我在选项卡栏中,这不起作用(UITabBar 保持横向大小)。

谢谢你的帮助

4

2 回答 2

2

您可以为 MPMovieplayer 使用单独的视图控制器。您不必覆盖

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在原始视图控制器中。

如果您使用的是MPMoviePlayerViewController,那么一切都已经为您设置好了,因为该方法shouldAutorotateToInterfaceOrientation:默认返回 YES。您可以将其用作子视图或通过调用以模态方式呈现它
presentMoviePlayerViewControllerAnimated:

于 2010-10-26T06:06:07.687 回答
1

检查一下:MPMoviewPlayerController 全屏播放旋转,底层 UIViewController 仅具有纵向模式(不允许旋转)

也许问题有点不同,但解决方案可能是一样的。

于 2011-02-16T14:40:04.557 回答