我刚刚在 XCode 4.5 上打开了我的 iPad 项目。我的应用程序设计为在横向模式下运行。它在以前版本的 XCode 上完美运行。但是在 XCode 4.5 上,它旋转了 90°(四分之一圈),屏幕右侧有一个空白区域(我的 View 大小正确,但超出了屏幕)。它看起来像这样:
我检查了以下帖子但没有帮助:
ios6 Rotation issue from landscape to portrait mode
Set orientation to landscape mode in xcode 4.5 GM IOS 6
有人遇到过这个问题吗?
如有任何帮助,我们将不胜感激!
最佳答案
谢谢大家的回复。我终于找到了解决方案。
首先,检查目标摘要菜单中所有启动图像的方向和大小是否正确(项目的蓝色图标 => 目标 => 摘要 => 在底部滚动);如果尺寸或方向不正确,您会在未正确设置的启动图像上收到警告。
到目前为止,我有一个具有这种结构的项目(旧的 XCode 时尚):
AppDelegate.h
和 .mRootViewController.h
和 .m- a
MainWindow-Iphone.xib
和MainWindow-iPad.xib
(在 Interface Builder 中链接了RootViewController
;请参见下面的屏幕截图相对于RootViewController
的黄色/棕色图标(内部有一个正方形)
下面是它的截图:
这是我的 AppDelegate 的 applicationDidFinishLaunching: 方法中的代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[rootViewController view]];
[window makeKeyAndVisible];
}
我所做的是更接近您在使用 XCode 4.5 创建空项目时获得的结构。因此:
- 我删除了
MainWindow.xib
和MainWindow-iPad.xib
,现在以编程方式创建了我的窗口(更清晰更好,以确保它适合任何屏幕的大小) - 我删除了在我的
Info.plist
中定义的“Main nib file base name”和“Main nib file base name (iPad)”键(并设置为MainWindow.xib
和MainWindow-iPad.xib
) - 我添加了空的
RootViewController_iPhone.xib
和RootViewController_iPad.xib
我更改了我的
applicationDidFinishLaunching
方法中的代码,如下所示:- (void)applicationDidFinishLaunching:(UIApplication *)application { NSLog(@"applicationDidFinishLaunching"); self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_iPhone" bundle:nil]; } else { self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_iPad" bundle:nil]; } self.window.rootViewController = self.rootViewController; [self.window makeKeyAndVisible];
现在,一切正常!方向在 iPad 上是正确的!而且它比以前更清楚了 :) 我什至不必更改已弃用的方法,例如
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
顺便说一下,要确保所有 View 都是全屏(在 iPhone 5 上),请确保在 Interface Builder 中将 View 设置为“缩放以填充”模式,并单击“自动调整 subview 大小”。如果您的某些 View 无法缩放到全屏,这可能是由于您创建 Controller / View 的顺序所致(superView 仅在创建它(superView)时才向其 subview 发送通知)。要轻松解决此问题,只需在 - (void)viewDidLoad 方法
中添加以下代码:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
[self.view setFrame:CGRectMake(0,0,screenBounds.size.width,screenBounds.size.height)];
或使用:
[self presentModalViewController:myViewController animated:TRUE];
代替:
[self.view.superview addSubview:myViewController.view];
presentModalViewController
确实会向 subview 发送调整大小的通知。
希望这会有所帮助!
关于ios - X代码 4.5/iOS6 : orientation issue with my iPad app in Landscape mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12717951/