0
votes

In iPad my app I have 2 views, the first view can be portrait or landscape orientation but the second view should be landscape mode. So I forcibly made the second view to be shown in Landscape mode using the below

[[UIApplication sharedApplication] setStatusBarOrientation:
         UIInterfaceOrientationLandscapeRight];

But what my problem is after coming to the second view when I check the device orienatation it returns “Portrait” . but the second view is always in Landscape mode. But why I get the wrong orientation.

Thanks for any help

1
you should have two UIViewControllers, with the shouldAutorotateToInterfaceOrientation method overwrited so they will different behaviour in both situations - JonLOo

1 Answers

2
votes

To set the orientation, a UIViewController or similar has a function that you can overwrite.

Specifically, check out this apple doc and scroll down to "shouldAutorotateToInterfaceOrientation:".

Code to force landscape mode should look something like:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown))
{
    return NO;
}
else if ((interfaceOrientation==UIInterfaceOrientationLandscapeLeft)||(interfaceOrientation==UIInterfaceOrientationLandscapeRight))
{
    return YES;
}
else {
    return YES;
}
}

This code should be contained in a view controller object, and is automatically called when the view controller is initiated.