我正在构建一个由 RootViewController 控制的具有多个 UIViewController 的应用程序。目前在 plist 中,应用程序默认为 LandscapeRight。
假设我有以下可以加载到 RootViewController 中的文件:
- IntroView(仅限横向)
- LandscapeView(仅限横向)
- PortraitView(仅限纵向)
我还在 RootViewController 的 shouldAutorotateToInterfaceOrientation 中添加了以下内容:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
所以一切都很好,直到我加载到 PortraitView 并在 viewWillAppear 我添加以下内容(类似于这个线程
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
self.view.center = CGPointMake(240.0f, 160.0f);
}
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
这会在 PortraitView 中正确加载,但现在我的问题是,在我的 PortraitView 中有 2 个子视图,我想在它们之间翻转,但是因为我旋转了我的视图 UIViewAnimationTransitionFlipFromLeft 实际上使它从上到下而不是从左到右翻转。我一生都无法弄清楚如何告诉 PortraitView 它在 Portrait 中。
当我检查 [[UIDevice currentDevice] 方向]; 它告诉我它在风景中。当我尝试使用 shouldAutorotateToInterfaceOrientation 并将其设置为仅纵向时,它将旋转我的视图,因此它不再正确。
希望这是有道理的!整天都在看这个问题。
谢谢!