ios - X代码 4.5/iOS6 : orientation issue with my iPad app in Landscape mode

标签 ios xcode ipad ios6 xcode4.5

我刚刚在 XCode 4.5 上打开了我的 iPad 项目。我的应用程序设计为在横向模式下运行。它在以前版本的 XCode 上完美运行。但是在 XCode 4.5 上,它旋转了 90°(四分之一圈),屏幕右侧有一个空白区域(我的 View 大小正确,但超出了屏幕)。它看起来像这样:

The view (red) rotated of 90° and going of the screen in landscape mode

我检查了以下帖子但没有帮助:

orientation issue in ios6

ios6 Rotation issue from landscape to portrait mode

Set orientation to landscape mode in xcode 4.5 GM IOS 6

有人遇到过这个问题吗?

如有任何帮助,我们将不胜感激!

最佳答案

谢谢大家的回复。我终于找到了解决方案。

首先,检查目标摘要菜单中所有启动图像的方向和大小是否正确(项目的蓝色图标 => 目标 => 摘要 => 在底部滚动);如果尺寸或方向不正确,您会在未正确设置的启动图像上收到警告。

到目前为止,我有一个具有这种结构的项目(旧的 XCode 时尚):

  • AppDelegate.h 和 .m
  • RootViewController.h 和 .m
  • a MainWindow-Iphone.xibMainWindow-iPad.xib(在 Interface Builder 中链接了 RootViewController;请参见下面的屏幕截图相对于 RootViewController 的黄色/棕色图标(内部有一个正方形)

下面是它的截图:

My old project structure

这是我的 AppDelegate 的 applicationDidFinishLaunching: 方法中的代码:

- (void)applicationDidFinishLaunching:(UIApplication *)application {  

     [window addSubview:[rootViewController view]];
     [window makeKeyAndVisible];

}

我所做的是更接近您在使用 XCode 4.5 创建空项目时获得的结构。因此:

  1. 我删除了 MainWindow.xibMainWindow-iPad.xib,现在以编程方式创建了我的窗口(更清晰更好,以确保它适合任何屏幕的大小)
  2. 我删除了在我的 Info.plist 中定义的“Main nib file base name”和“Main nib file base name (iPad)”键(并设置为 MainWindow.xib MainWindow-iPad.xib)
  3. 我添加了空的 RootViewController_iPhone.xibRootViewController_iPad.xib
  4. 我更改了我的 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/

相关文章:

ios - 比较两个具有特定约束的 NSDates

ios - 如何知道 UILabel 中的单词是否被剪切

iphone - 将 View Controller 类拆分为 VC 和自定义类的规则是什么?

ios - 如何永久修复 Xcode 5 SpringBoard 无法启动应用程序,错误为 : -3

ios - 如何在 iOS 9 正式发布之前提交 iOS 9 的应用程序更新?

iphone - 从 uitableviewcell 获取文本输入

iphone - Objective C 中维基百科的 API?

ios - 跳板[48] <警告> : High Priority Push: [Bundle ID] - BAR Disabled

使用 Xcode UI 测试的 Swift 异步事件处理

iOS 应用商店评论崩溃