I'm working on an application that operates entirely in landscape mode (UIStatusBarHidden=YES and UIInterfaceOrientation=UIInterfaceOrientationLandscapeRight). I'm using a NavigationController, with my rootViewController (MainViewController) setup like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
In my MainViewController, I'm loading the view like this:
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] applicationFrame]; // This returns a portrait frame
MainView *view = [[MainView alloc] initWithFrame:frame];
self.view = view;
[view release];
}
Then in MainView, I'm loading subviews like this:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.pdfView = [[PDFView alloc] initWithFrame:frame];
[self addSubview:pdfView];
}
returnself;
}
My issue is that MainView renders correctly in landscape mode (despite the frame passed into [MainView initWithFrame:] being in portrait), while the child PDFView renders into a portrait frame. I have also experimented with applying transforms in my [UIView initWithFrame:] implementations like this:
view.center = CGPointMake(view.frame.size.height/2.0, view.frame.size.width/2.0);
view.transform = CGAffineTransformRotate(view.transform, (M_PI/2.0));
But that doesn't seem to work since the frame value is incorrect. Ignoring the frame and creating one manually like this seems to work in some cases:
CGRectMake(0.0, 0.0, 480.0, 320.0)
But obviously doing manual adjustments like that is less than ideal.
Any ideas?