【发布时间】:2012-06-28 08:22:15
【问题描述】:
我的情况与this question 非常相似。我有一个通用的应用程序,其中 iPhone 为纵向,iPad 为横向,我使用 appDelegate.window.rootViewController = newScreen 在所有主屏幕之间切换; iPhone 应用程序完美运行。 iPad 应用程序有时会以纵向而不是横向的方式弹出屏幕。这是一些示例转换代码:
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
[appDelegate.window setRootViewController:(UIViewController*)v];
我也从this other question 尝试过这个:
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
[UIView
transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[appDelegate.window setRootViewController:(UIViewController*)v];
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
但没有任何东西可以解决它。
还尝试使用 [appDelegate.window makeKeyAndVisable] 和 [appDelegate.window makeKeyWindow],希望这会“震撼”它做出正确的方向。
【问题讨论】:
-
这是一种切换视图控制器的特殊方式,我以前从未见过,但它可能会起作用。您是否在视图控制器中添加了适当的
-(BOOL)shouldAutorotateToInterfaceOrientation:?那应该是确定界面方向的地方。 -
我确实做到了。看起来像这样: if (IS_IPAD()) { return UIInterfaceOrientationIsLandscape(interfaceOrientation); } return (interfaceOrientation == UIInterfaceOrientationPortrait);
-
嗯。您可以尝试切换到不太严格的方式来切换 VC,例如通过使用固定(空白)视图控制器,并以模态方式呈现您的各种视图。这可能会更可靠地保持界面方向固定。
-
这是一个完整的应用程序,我只是在上面添加了 iPad……如果我能以一种侵入性较小的方式修复它,我更愿意,但我会记住这一点。谢谢^^
-
嗨,马修,您找到问题的答案了吗?
标签: ios nib uiinterfaceorientation uiapplicationdelegate