当我的整个应用程序处于纵向模式锁定时,以横向模式播放全屏视频

Mon*_*tel 5 landscape objective-c uiinterfaceorientation ios

我希望在全屏模式下以横向模式播放视频.我的应用程序锁定在纵向模式.如何实现这一点.请帮我.提前致谢

Eyz*_*uky 9

swift中最简单的解决方案3将此添加到您的应用代理:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if window == self.window {
        return .portrait
    } else {
        return .allButUpsideDown
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 伙计,你摇滚!简单而优雅的解决方案 你救了我的一天.谢谢. (2认同)

Pra*_*iya 2

我已经在我的应用程序中完成了此操作。为此,您需要检查您想要播放视频的视图控制器。

  • 您要做的第一件事是在项目目标中检查“设备方向”为“纵向”、“横向左”、“横向右”

  • 在您的 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;
    }
    
    Run Code Online (Sandbox Code Playgroud)