Play fullscreen in landscape mode when my entire app is in portrait mode lock mode

I want to play the video in landscape mode in full screen. And my application is blocked in portrait mode. How to implement it. Please help me. thanks in advance

+5
source share
4 answers

I did this in my application. To do this, you need to check that your viewcontroller is where you want to play the video.

  • The first thing you need to do is check the orientation of the device in portrait, landscape, left, on the right side of your project.

  • In the AppDelegate app, enter the code below

    -(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
source

The easiest solution in quick 3 Add this to your application delegate:

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

Just call - viewDidAppear: submitted view controller.

Another way:

First, you must understand that in order to open at least one view of more than 100 in the landscape, your application must support landscape orientation and portfolio. This is the default, but you can check it in your target settings, General tab, Deployment Details section

Then, since you have allowed both landscape and portrait for the entire application, you will only need to tell the portrait — only the UIViewController — that it should not be autorotated by adding this implementation of the method: -

 - (BOOL)shouldAutorotate { return NO; } 

Finally, for your specific controller only for the landscape, and since you said that you represented it as a modality, you can simply implement these methods: -

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

Hope this helps :)

+1
source

Having looked at this page for almost the whole day, I finally figured out a solution to save working time for everyone,

Go to the project navigator, select your project and in general select only potrait in the device orientation.

Also make sure you use modal segue to show the LandscapeController.

Now add this to your controller where you need 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 what are these guys.

+1
source

Source: https://habr.com/ru/post/1247577/


All Articles