Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force portrait orientation while pushing from landscape View Controller

App Support: iOS6+

My app works in both portrait and landscape. But 1 controller should only works in a Portrait.

The problem is that when I am in landscape and push the view controller the new viewcontroller is in landscape as well until I rotate it to portrait. Then it's stuck in portrait as it should be.

Is it possible to always make it appear in portrait? Even if its parent is pushing it in landscape?

All the following code doesn't help

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 

And this code works until and unless i am not pushing from landscape How to force a UIViewController to Portrait orientation in iOS 6

like image 898
Tariq Avatar asked Jan 31 '13 19:01

Tariq


People also ask

How do I fix the orientation in Swift?

Set the supportedInterfaceOrientations property of specific UIViewControllers like this: class MyViewController: UIViewController { var orientations = UIInterfaceOrientationMask. portrait //or what orientation you want override var supportedInterfaceOrientations : UIInterfaceOrientationMask { get { return self.

How do I change orientation mode?

Select the Start button, then type settings. Select Settings > System > Display, and choose a screen orientation from the drop-down list next to Display orientation.

How do I change the orientation of Xcode?

Open project in Xcode ( ios/Runner. xcworkspace ), choose Runner in the project navigator, select Target Runner and on Tab General in section Deployment Info we can setup Device Orientation : Setup a device orientation in Xcode.


1 Answers

I solved this by adding following lines in ViewDidLoad

UIViewController *c = [[UIViewController alloc]init]; [self presentViewController:c animated:NO completion:nil]; [self dismissViewControllerAnimated:NO completion:nil]; 
like image 148
Tariq Avatar answered Oct 09 '22 04:10

Tariq