2010-10-18 66 views
24

从iOS 3.2开始,MPMoviePlayerController类允许在视图层次结构中嵌入电影。 现在我遇到了这个问题:我通过放置MPMoviePlayerController的一个实例来创建我的肖像视图。当用户触摸“全屏”按钮时,该视图进入全屏模式,但视图保持纵向。当用户旋转设备时,全屏电影视图不会自动旋转,因为我的应用禁止横向界面方向。 因此,为了允许电影播放器​​全屏视图的自动旋转,我改变了我的视图控制器shouldAutorotateToInterfaceOrientation:如果 - 且仅当 - 如果 - 电影播放器​​处于全屏模式时才返回YES风景。 这很好地工作:当用户进入全屏,然后旋转到风景时,播放器会自动旋转到横向并填充整个屏幕。MPMoviePlayerController重定向肖像到风景并返回到肖像(iOS 4.1)

// 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保持横向大小)。

感谢您的帮助

+0

您是否找到解决方案?我处于相同的情况,我找不到解决方案。 – klefevre 2013-04-18 09:08:03

+0

理论上用iOS6引入的新方法来管理定位,这个问题可以通过直接设置每个视图控制器方向来解决。这可以通过使用向每个视图控制器请求方向权限的新方法来完成。 – viggio24 2013-04-18 13:08:34

回答

2

您可以为MPMovieplayer使用单独的视图控制器。你不必重写

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在原来的视图控制器。

如果您使用的是MPMoviePlayerViewController,则所有设置都已正确设置,因为默认情况下,方法shouldAutorotateToInterfaceOrientation:将返回YES。你可以使用它作为一个子视图或致电
presentMoviePlayerViewControllerAnimated: