ios – MPInlineVideoFullscreenViewController和AVFullScreenViewController第一次进入纵向模式

在MPMovieplayer中有太多与风景问题相关的问题.我的应用程序是纵向模式.但我想在横向模式下观看视频.我已经拥有视频的横向/纵向功能.我使用以下代码:

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
    [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
    return UIInterfaceOrientationMaskPortrait;
}

}

该代码在iOS 7和iOS8中都运行良好.
但问题是视频首先在纵向模式下打开,而设备处于横向模式.方向改变后,应用程序工作正常.

提前致谢.

最佳答案 经过漫长的研发和不同的方法,花了2-3天.最后我在朋友的帮助下得到了答案.如果我们的视图控制器处于纵向模式,则以下代码无法在景观中推动播放器视图视图.

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
[[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{
  return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;

}

在我的情况下问题是我的UIWebView容器视图控制器非常时间处于纵向模式.我不知道在UINavigationController中推送ViewController之后,没有为该ViewController调用定向方法.

-(BOOL)shouldAutorotate;  
-(NSUInteger)supportedInterfaceOrientations;

要解决此问题,我将在ViewDidLoad方法中添加以下代码

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

并在viewWillDisappear中的以下代码中

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

上面的代码最终解决了我的问题.

感谢所有支持我解决这个问题的人.

点赞