相关疑难解决方法(0)

MPMoviewPlayerController全屏播放旋转,底层UIViewController仅限纵向模式(不允许旋转)

你好,

我有一个简单的应用程序,它包含带有两个UIViewControllers的UITabBarController.两个UIViewControllers都只是纵向(不允许旋转).一个UIViewController的UIView确实包含MPMoviePlayerController的视图,允许在该视图中播放视频,并可通过控件(MPMovieControlStyleEmbedded)使其全屏显示.代码很简单,看起来像......

__moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"MOVIE_URL"]];
__moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
__moviePlayer.view.frame = CGRectMake( 10, 10, 300, 200 );
__moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
__moviePlayer.shouldAutoplay = NO;
[__moviePlayer prepareToPlay];  
[self.view addSubview:__moviePlayer.view];
Run Code Online (Sandbox Code Playgroud)

...这确实很有效,除非用户切换到全屏播放,我希望允许旋转以允许横向播放.旋转不起作用,因为UITabBarController不允许它(以及两个UIViewControllers).

所以,我尝试了两种方法,但它们都没有按预期工作.

1)Subclassed UITabBarController

我添加了属性BOOL __allowRotation,如果设置为YES,我在UITabBarController的shouldAutorotateToInterfaceOrientation方法中返回YES.

我正在侦听MPMoviePlayerDidEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification通知,将此属性设置为YES和NO.

它确实有效,但问题是,当用户以横向结束视频播放时,底层视图不会旋转回纵向.旋转回纵向的唯一方法是使用私有API,这不是没有.

2)视图/层转换

我也尝试过监听MPMoviePlayerDidEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification通知.

当我收到MPMoviePlayerDidEnterFullscreenNotification时,我正在启动UIDevice方向通知以获取设备方向.我正在尝试根据当前的设备方向转换MPMoviePlayerController的视图层,但它有点免疫,因为它什么都不做.我可以分配任何转换属性,但它什么都不做.

它没有做任何不太正确的事情.当我在旋转期间应用变换时,当我从全屏切换回嵌入式视频播放时,我可以看到此变换的效果.

3)单独的UIWindow

我还没有测试过这个,但我发现MPMoviePlayerController创建单独的UIWindow用于全屏播放,应该可以通过[[UIApplication sharedApplication] windows]访问.这解释了为什么在全屏播放期间不应用转换.

但是我非常不喜欢这个解决方案,因为UIWindow无法识别,我不想使用像objectAtIndex:1这样的魔术常量,或者将转换应用到除主要部分之外的所有UIWindows等.

除了可以修改底层实现并且它将停止工作的事实.

所以,问题是,当底层UIView(即UIView的UIViewController)禁止旋转并仅允许纵向时,如何允许MPMoviePlayerController全屏播放仅旋转?

iphone cocoa-touch rotation mpmovieplayercontroller uitabbarcontroller

12
推荐指数
2
解决办法
2万
查看次数