I'm developing an iPad app that needs to be restricted to landscape mode. I've got a root view controller
and a subview controller. I add the sub view controller to the root view controller and set their
frames to 1024x768. I restricted the app to landscape mode in info.plist and in my view controllers'
shouldAutorotateToInterfaceOrientation:interfaceOrientation
method. However, the dimensions for
the subview get reset to 768x1024 sometime before the viewDidAppear
method which makes it appear
as if it's in portrait mode.
The strange part is if I set the frame for the subview so that the width or height are something other than the screen dimensions, for example: CGRectMake(0, 0, 1024, 767) or CGRectMake(0, 0, 1024, 769), it doesn't get reset and displays in what looks like landscape mode.
So my question is, what's causing this behavior. And what's the best way to simply default all views to landscape mode
Here's my root view controller:
// INTERFACE
#import <UIKit/UIKit.h>
#import "ScrapViewController.h"
@interface ViewController : UIViewController
{
ScrapViewController *svc;
}
@end
// IMPLEMENTATION
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
self.view.frame = CGRectMake(0, 0, 1024, 768);
svc = [[SubViewController alloc] init];
svc.view.backgroundColor = [UIColor redColor];
svc.view.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:svc.view];
NSLog(@"viewDidLoad rvc %f,%f", self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"viewDidLoad svc %f,%f", svc.view.frame.size.width, svc.view.frame.size.height);
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
@end
Here's my sub view controller
// INTERFACE
#import <UIKit/UIKit.h>
@interface SubViewController : UIViewController
@end
// IMPLEMENTATION
@implementation SubViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
@end