0

I have an app with an UITableView at the home screen. I made this view to always be in landscape orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

If the user picks a row he will be taken to a UIPageViewController view. This second view can rotate to landscape and portrait. The problem is when I am in portrait mode on the UIPageViewController and I press the go back button, the first view which is supposed to be always in landscape mode now is in portrait. After I rotate it, it gets into landscape and stays there.

I was wondering maybe if there is a way to make my home screen go automatically into landscape when I go back to it.

Teo
  • 3,394
  • 11
  • 43
  • 73
  • If you want this app to get in the app store I suggest you support portrait for all your screens. – ader May 15 '12 at 15:36

6 Answers6

2

Try the following

  1. Create the view of your main screen in app in interface builder in Landscape mode.
  2. Create uiview oultlet in interface class and connect it to above view.
    IBOutlet UIVIew *myView;
  3. Then in the viewDidLoad method set this self.view = self.myView;
Jack
  • 10,943
  • 13
  • 50
  • 65
Harshit Gupta
  • 1,200
  • 12
  • 27
1

If you want to make a screen in a particular orientation then you can create a CustomNavigation controller and then present it in your app. You have to only return supportedInterfaceOrientations in this. If you want more detail and sample code click here.

Henry
  • 21
  • 2
0

Call shouldAutorotateToInterfaceOrientation manually when you go back. You can not force a "real" orientation change, that's a OS thing.

jimpic
  • 5,360
  • 2
  • 28
  • 37
  • doesn't seem to work... I called it in ``viewWillAppear`` and there is no effect – Teo May 15 '12 at 10:05
  • ok, a little confusing, sorry. this will not emulate the orientation change event, but you can do your UI transformation "by hand" in there - that's how I would do it. – jimpic May 15 '12 at 10:08
0

As said in the view controller programming guide, you can have a alternate landscape interface and before coming to home screen from any other view, you can check the orientation and push the corresponding interface onto the screen

Read this SO question and answer for better understanding of launching an app in landscape.Also go through above apple programming guide which i pointed to.

Community
  • 1
  • 1
Sreeram
  • 3,160
  • 6
  • 33
  • 44
0

If you use the UINavigationViewController methods(pushViewController:animated: and popViewControllerAnimated:), the views will inherit the previous view's orientation.

On the other hand, if you use presentModalViewController:animated: and dismissModalViewControllerAnimated: methods, everything works perfectly. Hope this helped!

Teo
  • 3,394
  • 11
  • 43
  • 73
0

Use this, change the UIInterfaceOrientationLandscapeLeft to required orientation type as UIDeviceOrientationPortrait, UIDeviceOrientationLandscapeLeft etc.

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