Can I make one look in my application in Landscape and all the others in portrait mode?

My iPhone app is currently in portrait mode.

But I need to play the video in widescreen mode and draw some ui elements that work best in portrait mode. Also, some text input will be displayed from time to time, so the keyboard should also appear as a portrait.

Is it possible to tell the UIViewController when loading that it needs to go to Landscape, the parent view on the stack will be Portrait.

I do not want the user to rotate, I want to decide which screens will be landscapes and whether it will be a portrait.

So, for display, everyscreen / view in my application will have a portrait, except for the one that I would like to make Landscape. It can be done?

Thanks a lot, code

+4
source share
3 answers

In your UIViewController you implement this method

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations BOOL result = NO; if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { result = YES; } return result; } 

And you will return YES for the orientation you want to maintain.
This method will call your UIViewController when it is loaded, so it will not receive a call every time you enter this UIViewController.


And if you want to be absolutely sure that all other UIViewControllers are the desired orientation, add this method to them.

+2
source

Yup, use [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]]; or portrait for portrait orientation.

+1
source
 override func viewWillAppear(animated: Bool) { let value = UIInterfaceOrientation.LandscapeRight.rawValue UIDevice.currentDevice().setValue(value, forKey: "orientation") UIApplication.sharedApplication().statusBarHidden = true } override func shouldAutorotate() -> Bool { return true } 

and change it to what you want (LandscapeRight, LandscapeLeft or Portrait)

0
source

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


All Articles