在横屏模式下全屏播放video,当我的整个应用程序locking在纵向模式下

我想以全屏模式播放横向模式的video。 而我的应用程序locking在肖像模式。 如何实现这一点。 请帮帮我。 提前致谢

我已经完成了我的应用程序。 要做到这一点,你需要检查你的视图控制器,你想播放video。

  • 您需要做的第一件事是在您的项目目标中检查纵向的设备方向,左侧的横向,右侧的横向

  • 在你的AppDelegate做下面的代码

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ UIStoryboard *mainStoryboard; if (IS_IPHONE) { mainStoryboard= [UIStoryboard storyboardWithName:@"Main" bundle: nil]; } else{ mainStoryboard= [UIStoryboard storyboardWithName:@"Main_iPad" bundle: nil]; } ViewControllerThatPlaysVideo *currentViewController= ViewControllerThatPlaysVideo*)[mainStoryboard instantiateViewControllerWithIdentifier:@"postDetailView"]; if(navigationController.visibleViewController isKindOfClass: [ViewControllerThatPlaysVideo class]]){ if([currentViewController playerState]) return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait; return UIInterfaceOrientationMaskPortrait; } return UIInterfaceOrientationMaskPortrait; } 

swift中最简单的解决scheme3将其添加到您的应用程序委托中:

 func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if window == self.window { return .portrait } else { return .allButUpsideDown } } 
 NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 

只需在视图控制器的- viewDidAppear:调用它即可。

其他方式 :

首先,你必须明白,为了打开超过100个景观中的一个视图,你的应用应该允许横向和纵向的界面方向。 默认情况下,您可以在目标设置,常规选项卡,部署信息部分查看它

然后,因为你允许横向和纵向整个应用程序,你将不得不告诉每个只有肖像的UIViewController ,它不应该自动旋转,添加此方法的实现: –

 - (BOOL)shouldAutorotate { return NO; } 

最后,对于你的特定的景观专用控制器,因为你说你正在以模态方式呈现它,你可以实现这些方法:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; // or Right of course } -(UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

希望这会帮助:)