iOS – video不能仅在iOS7上通过iPhone旋转?

我做了什么?

我正在MPMoviePlayerViewController的扩展类中播放video,并已经实现了如下的方向function

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ return FALSE; } else{ return TRUE; } } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self setControlsPositions:toInterfaceOrientation]; } -(BOOL)shouldAutorotate { return YES; } 

我面临什么问题?

应用程序工作正常,直到iPhone6上的iOS6 Almong与iPad(与iOS7),但video不会旋转通过安装iOS7的iPhone。

这个问题的原因是什么?如何解决?

更新

我发现,如果setMovieSourceType设置为MPMovieSourceTypeUnknown ,则video会旋转,但设置为“MPMovieSourceTypeStreaming”时不会旋转

在苹果要我给他们一个样本,我在iOS-7中报告的错误,我发现我没有推视图控制器,而是我把视图添加到窗口。 在这种情况下,其他视图控制器确实获取方向事件,但MPMoviePlayerViewController子类没有,所以我只是呈现视图控制器,而不是添加其视图,它的工作。

试试这个解决scheme

在你的AppDelegate.h

 @property (nonatomic, assign) BOOL *fullScreenVideoIsPlaying; 

在你的AppDelegate.m

 @synthesize fullScreenVideoIsPlaying; - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSUInteger orientations = UIInterfaceOrientationMaskPortrait; if (self.fullScreenVideoIsPlaying) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { if(self.window.rootViewController){ UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; orientations = [presentedViewController supportedInterfaceOrientations]; } return orientations; }} 

在你的ViewController:

viewDidLoad方法中:

  myDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil]; 

并在同一个类中添加这两个方法:

 -(void) movieStarted:(NSNotification*) notif { myDelegate.fullScreenVideoIsPlaying = YES; } -(void) youTubeFinished:(movieFinished*) notif { myDelegate.fullScreenVideoIsPlaying = NO; } 

旋转方法随iOS 6更改,您需要将iOS 6旋转方法添加到视图控制器:

 - (BOOL)shouldAutorotate { return YES: } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } 

而且您需要将Supported interface orientations与支持的方向添加到您的应用info.plist

从iOS 6.0发布信息:

UIViewController类具有支持以下行为的新接口:

  • 新的界面提供了一个更清晰的path来pipe理和跟踪界面旋转。

我认为设备旋转被locking在控制中心,导致它在ipad ios 7中运行良好。