问题描述
从iOS 3.2开始,MPMoviePlayerController类允许在视图层次结构中嵌入电影。
现在我面临这个问题:我通过放置一个MPMoviePlayerController实例来创建我的纵向视图。当用户触摸全屏按钮时,此视图以全屏模式进入,但视图仍保持纵向。当用户旋转设备时,全屏影片视图不会自动旋转,因为我的应用禁止横向界面方向。
因此,为了允许电影播放器全屏视图的自动旋转,我改变了我的视图控制器shouldAutorotateToInterfaceOrientation:方法如果 - 并且仅当 - 电影播放器处于全屏模式时返回YES。
这非常有效:当用户全屏进入然后旋转到横向时,播放器会自动旋转到横向并填充整个屏幕。
Since iOS 3.2 the MPMoviePlayerController class allows to embed a movie in the view hierarchy.Now I'm facing this issue: I create my portrait view by placing an instance of MPMoviePlayerController. When the user touch the "fullscreen" button this view enters in fullscreen mode but the view remains in portrait. When the user rotates the device the fullscreen movie view is not auto-rotated as my app forbids landscape interface orientation.So in order to allow auto-rotation of movie player fullscreen view, I changed my view controller shouldAutorotateToInterfaceOrientation: method to return YES for landscape if - and only if - the movie player is in full screen mode.This works perfectly: when the user enters in full screen and then rotates to landscape the player is auto-rotated to landscape and fills the entire screen.
// 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);
}
现在,当我在全屏触摸完成按钮时出现问题保持在景观中的视图。全屏关闭,然后我看到的是我的原始视图自动旋转:但我不希望这种自动旋转。
Now the issue arises when I touch the "Done" button in the full screen view while remaining in landscape. The full screen closes and then what I see is my original view autorotated: but I don't want this auto-rotation.
部分但不可接受的解决方案是监听MPMoviePlayerDidExitFullscreenNotification,如果界面旋转为横向,则强制重新定向以使用未记录的私有函数:
A partial, but not acceptable solution, is to listen for "MPMoviePlayerDidExitFullscreenNotification" and, if the interface is rotated to landscape, force re-orientation to using the undocumented and private function:
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]
这有效,但不能接受这个用法方法是禁止的。
This works but is not acceptable as usage of this method is forbidden.
我试图使用 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]
强制定位但是我在标签栏中这不起作用(UITabBar仍然是景观大小)。
I tried to force orientation using [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]
but as I'm in a Tab Bar this doesn't work (the UITabBar remains Landscape-sized).
感谢您的帮助
推荐答案
您可以为MPMovieplayer使用单独的视图控制器。您不必覆盖
You can use a separate view controller for MPMovieplayer. You don't have to override the
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
在原始视图控制器中。
如果您使用,一切都已经很好地为你设置了,因为方法 shouldAutorotateToInterfaceOrientation:
默认会返回YES。您可以将其用作子视图或通过调用以下方式呈现它:
presentMoviePlayerViewControllerAnimated:
if you are using MPMoviePlayerViewController, everything is already set nicely for you, as the method shouldAutorotateToInterfaceOrientation:
will return YES by default. You can use it as a subview or present it modally by callingpresentMoviePlayerViewControllerAnimated:
这篇关于MPMoviePlayerController重定向纵向到横向和回到纵向(iOS 4.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!