我正在开发一个完全以横向模式运行的应用程序(UIStatusBarHidden=YES和UIInterfaceOrientation=uiInterfaceOrientationAndScapeRight)。我使用的是NavigationController,rootViewController(MainViewController)设置如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] applicationFrame]; // This returns a portrait frame
MainView *view = [[MainView alloc] initWithFrame:frame];
self.view = view;
[view release];
}
然后在MainView中,我加载如下子视图:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.pdfView = [[PDFView alloc] initWithFrame:frame];
[self addSubview:pdfView];
}
returnself;
}
我的问题是,MainView在横向模式下正确渲染(尽管传递到[MainView initWithFrame:]的帧是纵向的),而子PDFView渲染到纵向帧。我还尝试在[UIView initWithFrame:]实现中应用转换,如下所示:
view.center = CGPointMake(view.frame.size.height/2.0, view.frame.size.width/2.0);
view.transform = CGAffineTransformRotate(view.transform, (M_PI/2.0));
但这似乎不起作用,因为帧值不正确。在某些情况下,忽略框架并手动创建这样的框架似乎是可行的:
CGRectMake(0.0, 0.0, 480.0, 320.0)
但很明显,像这样的手动调整并不理想。
有什么想法吗?