I have an iPhone app that supports all device orientations, but I have a specific modal view that I only want to display in landscape.
If the device is in landscape orientation it works fine, but if the device is physically held in portrait orientation it does not display the way I would like.
Because the device is held in a portrait orientation the image is cropped and the left and right sides are off the edges of the display. Since the image is only as high as the narrow dimension, the top and bottom shows the background of the parent view. If I then rotate the device into a landscape orientation everything is then fine.
In my research I frequently come across shouldAutorotateToInterfaceOrientation, but I believe that is an event that only gets fired when the device is physically rotated which does not apply to my situation. The device is physically held in portrait orientation but I want to display the view as if it was held in landscape.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight] is also mentioned but I have never seen that have any effect when I've tried using it.
So I guess my question is if there is a simple way to force the initial display of a view in an orientation different than the physical orientation of the device and exactly how to do it.
I am using the following logic to modally display my view:
TitleViewController *titleController = [[TitleViewController alloc] initWithNibName:@"TitleViewController" bundle:[NSBundle mainBundle]];
titleController.delegate = self;
titleController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:titleController animated:YES];
[titleController release];
I want to always display the modal view in a landscape orientation, even when the device is held in portrait.
UPDATE
Found a solution that works:
if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}
However, when dealing with the orientation UIInterfaceOrientationPortraitUpsideDown, it initially displays the view with the proper orientation but then shifts it back to a portrait orientation with clipped sides and shows the background above and below the image.
I have tried tweaking the angle to 270, -90, and other values but always reverts to portrait when in the UIInterfaceOrientationPortraitUpsideDown orientation.
Why?