MPMoviewPlayerController全屏播放旋转与底层的UIViewController只有纵向模式(旋转不允许) [英] MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)

查看:109
本文介绍了MPMoviewPlayerController全屏播放旋转与底层的UIViewController只有纵向模式(旋转不允许)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hallo,



我有一个简单的应用程序,它包含UITabBarController和两个UIViewControllers。两个UIViewController只是纵向(不允许旋转)。一个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];

...除非用户切换到全屏播放,风景播放。旋转不工作,因为UITabBarController不允许它(和两个UIViewController)。



所以,我尝试了两种方法,但没有一个按预期工作。 p>

1)子类UITabBarController



我添加了属性BOOL __allowRotation,是的,我在UITabBarController的shouldAutorotateToInterfaceOrientation方法中返回YES。



我正在监听MPMoviePlayerDidEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification通知,将此属性设置为YES和NO。 b
$ b

它可以工作,但问题是,当用户在横向结束视频播放时,底层视图不会旋转回纵向。回到肖像的唯一方法是使用私有API,这是没有的。



2)查看/图层转换 >

我也试过监听MPMoviePlayerDidEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification通知。



当我收到MPMoviePlayerDidEnterFullscreenNotification时,我开始UIDevice方向通知获取设备方向。我试图转换MPMoviePlayerController的视图层基于当前的设备方向,但它有点免疫,因为它什么也没有。我可以分配任何变换属性,但它什么都不做。



它没有什么不是很正确。当我在旋转期间应用转换时,当我从全屏切换回嵌入视频播放时,我可以看到这种转换的效果。



3)单独的UIWindow



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



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



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

问题



所以,问题是,如何允许MPMoviePlayerController全屏播放

解决方案

你可以尝试呈现新的UIViewController(UIView的UIViewController)与shouldAutorotate YES)模式,并添加__moviePlayer.view到此控制器,当它发送MPMoviePlayerWillEnterFullscreenNotification。当moviePlayer退出全屏时执行相反操作。


Hallo,

I have a simple application, which does contain UITabBarController with two UIViewControllers. Both UIViewControllers are portrait only (no rotation allowed). One UIViewController's UIView does contain MPMoviePlayerController's view to allow video playback inside this view with possibility to make it fullscreen via controls (MPMovieControlStyleEmbedded). The code is simple and does look like ...

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

... this does work perfectly unless user switches to fullscreen playback where I want to allow rotation to allow landscape playback too. Rotation doesn't work, because UITabBarController disallows it (and both UIViewControllers too).

So, I tried two approaches, but none of them does work as expected.

1) Subclassed UITabBarController

I did add property BOOL __allowRotation and if it is set to YES, I do return YES in UITabBarController's shouldAutorotateToInterfaceOrientation method.

I'm listening for MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification notifications to set this property to YES and NO.

It does work, but the problem is, that when the user ends video playback in landscape, underlying view is not rotated back to portrait. The only way to rotate back to portrait is to use private API, which is no no.

2) View/layer transformation

I also did try to listen for MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification notifications.

When I receive MPMoviePlayerDidEnterFullscreenNotification, I'm starting UIDevice orientation notifications to get device orientation. I'm trying to transform MPMoviePlayerController's view layer based on current device orientation, but it's kinda immune, because it does nothing. I can assign whatever to transform property, but it does nothing.

It does nothing is not quite correct. When I apply transformation during rotation, I can see effect of this transformation when I switch back from fullscreen to embedded video playback.

3) Separate UIWindow

I did not test this yet, but I've found somewhere that MPMoviePlayerController creates separate UIWindow for fullscreen playback, which should be accessible via [[UIApplication sharedApplication] windows]. This does explain why transformation is not applied during fullscreen playback.

But I quite dislike this solution, because the UIWindow can't be identified and I do not want to use magic constants like objectAtIndex:1 or apply transformation to all UIWindows except the main one, etc.

Beside the fact that the underlying implementation can be modified and it will stop working.

Question

So, the question is, how to allow MPMoviePlayerController fullscreen playback only rotation when underlying UIView (ie. UIView's UIViewController) prohibits rotation and allows portrait only?

解决方案

You can try to present new UIViewController (with shouldAutorotate YES) modally and add __moviePlayer.view into this controller when it sends MPMoviePlayerWillEnterFullscreenNotification. Do the opposite when moviePlayer exits fullscreen.

这篇关于MPMoviewPlayerController全屏播放旋转与底层的UIViewController只有纵向模式(旋转不允许)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆