相关疑难解决方法(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万
查看次数

当项目设置允许所有旋转时,禁用特定视图控制器中的旋转

之前问过一个问题.我面临着同样的问题,即电影播放器​​没有旋转,因为项目属性不允许旋转.这个问题只是在iPhone7上面对iPhone,所以我正在尝试另外的工作,我在项目属性中启用所有方向,但问题是,当我通过这样的功能禁用其他视图控制器中的旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
     return FALSE;
}

// Tell the system what we support
-(NSUInteger)supportedInterfaceOrientations
 {
return UIInterfaceOrientationPortrait;
}

- (BOOL) shouldAutorotate {
return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;

}
Run Code Online (Sandbox Code Playgroud)

视图控制器仍然旋转,我认为这是因为它允许在项目属性中.

所以问题是......

当项目设置允许所有旋转时,如何禁用特定媒体播放器视图控制器中的旋转?

要么

如何在项目属性(禁用旋转)上覆盖特定Media Player视图控制器中的旋转,这在iOS7中不起作用

iphone objective-c rotation mpmovieplayercontroller ios7

4
推荐指数
1
解决办法
2553
查看次数

在iOS 7中强制使用Landscape ViewController

我在纵向模式下有十多个ViewControllers,但无论设备的方向如何,我都需要在横向模式下强制使用一个.

objective-c ios

4
推荐指数
1
解决办法
2757
查看次数