Help me on device orientation
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 sec开发者_JAVA百科ond view is always in Landscape mode. But why I get the wrong orientation.
Thanks for any help
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.
精彩评论