当我的整个应用程序都锁定在竖屏模式下时,在横屏模式下播放视频全屏。

时间:2023-01-19 21:26:53

I want to play video in landscape mode in fullscreen. And my application is lock in portrait mode. How to implement this. Please help me. Thanks in advance

我想在全屏的横屏模式下播放视频。我的应用程序锁定为竖屏模式。如何实现这一点。请帮助我。谢谢提前

4 个解决方案

#1


2  

I've done this in on of my app. To do this you need to check that is your viewcontroller that where you want to play a video.

我已经在我的app上做了这个,要做这个你需要检查那是你想要播放视频的视图控制器。

  • The first thing you have to do is check Device Orientation to Portrait,Landscape left, Landscape right in your project target

    你要做的第一件事是检查设备朝向,横向左边,横向右边在你的项目目标

  • In your AppDelegate do the below code

    在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;
    }
    

#2


8  

Simplest solution in swift 3 Add this to your app delegate:

swift 3中最简单的解决方案添加到您的应用委托:

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

#3


1  

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

Just call it in - viewDidAppear: of the presented view controller.

只需在- viewDidAppear中调用:显示的视图控制器。

Another way :

另一种方法:

First, you have to understand that in order to open even just one view out of over 100 in landscape, your app should allow both landscape and portrait interface orientations. It is the case by default, but you can check it in your target's settings, General tab, Deployment Info section

首先,你必须明白,为了在超过100个横向视图中打开一个,你的应用程序应该同时允许横向和纵向的界面朝向。默认情况下是这样,但是您可以在目标的设置、General选项卡、部署信息部分进行检查。

Then, because you allowed both landscape and portrait for the entire app, you will have to tell every portrait-only UIViewController that it should not autorotate, adding this method's implementation:-

然后,因为您允许整个应用程序同时使用横向和纵向,所以您必须告诉每个仅使用纵向的UIViewController,它不应该是autorotate,添加这个方法的实现:-

- (BOOL)shouldAutorotate {
    return NO;
}

Finally, for your specific landscape-only controller, and because you said you are presenting it modally, you can just implement these methods:-

最后,对于您的特定的仅用于风景的控制器,并且因为您说您正在以模态方式呈现它,您可以实现这些方法:-

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

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Hope this will help :)

希望这能有所帮助。

#4


1  

After staring at this page for almost an entire day, I finally figured out a working time saving solution for all,

盯着这一页看了几乎一整天,我终于想出了一个人人都能节省工作时间的解决方案,

Go to the project navigator, select your project and in General select just potrait in device orientation.

转到项目导航器,选择您的项目,一般选择在设备方向上的potrait。

Also make sure that you're using a modal segue to show the landscapeController.

还要确保您正在使用modal segue来显示landscape apecontroller。

Now add this in your controller where in you want the landscape mode.

现在在你的控制器中添加这个在你想要的横屏模式中。

override func viewWillAppear(_ animated: Bool) {

    super.viewWillAppear(true)
}

override var shouldAutorotate: Bool {

    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {

    return .landscapeRight
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {

    return .landscapeRight
}

And that's it folks.

就是这样的人。

#1


2  

I've done this in on of my app. To do this you need to check that is your viewcontroller that where you want to play a video.

我已经在我的app上做了这个,要做这个你需要检查那是你想要播放视频的视图控制器。

  • The first thing you have to do is check Device Orientation to Portrait,Landscape left, Landscape right in your project target

    你要做的第一件事是检查设备朝向,横向左边,横向右边在你的项目目标

  • In your AppDelegate do the below code

    在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;
    }
    

#2


8  

Simplest solution in swift 3 Add this to your app delegate:

swift 3中最简单的解决方案添加到您的应用委托:

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

#3


1  

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

Just call it in - viewDidAppear: of the presented view controller.

只需在- viewDidAppear中调用:显示的视图控制器。

Another way :

另一种方法:

First, you have to understand that in order to open even just one view out of over 100 in landscape, your app should allow both landscape and portrait interface orientations. It is the case by default, but you can check it in your target's settings, General tab, Deployment Info section

首先,你必须明白,为了在超过100个横向视图中打开一个,你的应用程序应该同时允许横向和纵向的界面朝向。默认情况下是这样,但是您可以在目标的设置、General选项卡、部署信息部分进行检查。

Then, because you allowed both landscape and portrait for the entire app, you will have to tell every portrait-only UIViewController that it should not autorotate, adding this method's implementation:-

然后,因为您允许整个应用程序同时使用横向和纵向,所以您必须告诉每个仅使用纵向的UIViewController,它不应该是autorotate,添加这个方法的实现:-

- (BOOL)shouldAutorotate {
    return NO;
}

Finally, for your specific landscape-only controller, and because you said you are presenting it modally, you can just implement these methods:-

最后,对于您的特定的仅用于风景的控制器,并且因为您说您正在以模态方式呈现它,您可以实现这些方法:-

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

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Hope this will help :)

希望这能有所帮助。

#4


1  

After staring at this page for almost an entire day, I finally figured out a working time saving solution for all,

盯着这一页看了几乎一整天,我终于想出了一个人人都能节省工作时间的解决方案,

Go to the project navigator, select your project and in General select just potrait in device orientation.

转到项目导航器,选择您的项目,一般选择在设备方向上的potrait。

Also make sure that you're using a modal segue to show the landscapeController.

还要确保您正在使用modal segue来显示landscape apecontroller。

Now add this in your controller where in you want the landscape mode.

现在在你的控制器中添加这个在你想要的横屏模式中。

override func viewWillAppear(_ animated: Bool) {

    super.viewWillAppear(true)
}

override var shouldAutorotate: Bool {

    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {

    return .landscapeRight
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {

    return .landscapeRight
}

And that's it folks.

就是这样的人。