我正在开发一个完全在横向模式下运行的应用程序(UIStatusBarHidden=YES 和 UIInterfaceOrientation=UIInterfaceOrientationLandscapeRight)。我正在使用 NavigationController,我的 rootViewController (MainViewController) 设置如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
在我的 MainViewController 中,我正在加载如下 View :
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] applicationFrame]; // This returns a portrait frame
MainView *view = [[MainView alloc] initWithFrame:frame];
self.view = view;
[view release];
}
然后在 MainView 中,我加载如下 subview :
- (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)
但显然像这样进行手动调整并不理想。
有什么想法吗?
最佳答案
我不知道这对您的情况是否有帮助,但请确保您的所有 View 和控件都支持自动旋转。 UINavigationController 没有,UITabBarController 也没有。如果选项卡栏 Controller 的任何 subview 不支持自动旋转,则选项卡栏 Controller 将停止支持它。我必须创建自己的 UINavigationController 并使其继承自 UINavigationController,然后实现自动旋转。由于您完全在横向中执行应用程序,我不知道这是否有帮助,但它可能会让您开始走上解决方案的道路。
关于iphone - UINavigationController 自动旋转到横向不会更新 UIView 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/781361/