ios - 旋转在 iOS6 上表现不同

标签 ios xcode autorotate autolayout

我做了一个基于选项卡的应用程序。除了几个 View 之外,什么都不需要处于横向模式。它在 iOS5 上运行良好,我对结果非常满意。然而,对于 iOS6 并且没有弄乱任何东西,它现在旋转所有 View 并且结果并不好。

因为它是一个基于选项卡的应用程序,所以我需要的横向 View 是模态视图。这样我就不会弄乱标签栏,我只需要在构建选项的“支持的方向”设置中选择纵向并设置:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

关于我想要风景的观点。

现在在 iOS6 中,这个 View 也是纵向模式,无论如何,即使我旋转设备,它们也不会显示横向模式。同样,如果我允许“支持的方向”上的所有方向,它们都会旋转,无论我在上面的方法中放置什么。

在所有 View 中,我都没有选中 Storyboard上的“使用自动布局”框。

这里有什么帮助吗?

*编辑** 现在我看到了,我在设备上的应用程序工作正常。我安装了一个促销代码,而不是来自 Xcode,只是为了看看我的客户是否有问题。幸运的是他们不是。但问题仍然存在。

最佳答案

我找到的关于这个问题的文档中最重要的部分是:

When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window

为了让我的应用在 iOS 6 中完全支持自动旋转,我必须执行以下操作:

1) 我创建了 UINavigationController 的新子类,并添加了 shouldAutorotate 和 supportedInterfaceOrientation 方法:

// MyNavigationController.h:
#import <UIKit/UIKit.h>

@interface MyNavigationController : UINavigationController

@end

// MyNavigationController.m:
#import "MyNavigationController.h"
@implementation MyNavigationController
...
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
...
@end

2) 在 AppDelegate 中,我确实使用了我的新子类来显示我的根 ViewController(它是 introScreenViewController,一个 UIViewController 子类)并设置了 self.window.rootViewController,所以看起来:

    nvc = [[MyNavigationController alloc] initWithRootViewController:introScreenViewController];
    nvc.navigationBarHidden = YES;
    self.window.rootViewController = nvc;
    [window addSubview:nvc.view];
    [window makeKeyAndVisible];

关于ios - 旋转在 iOS6 上表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12536645/

相关文章:

ios - 在 ios 6 中强制自动旋转 View

ios6 autorotation portraitupsidedown 到 portrait

ios - 如何在标签中打印数组?

objective-c - 将 swift 类导入 Objective-C 可以,但某些自定义文件不行

ios - 使用 SWRevealViewController Controller 时如何注销?

objective-c - Objective-C (OSX) 中的程序目录

ios - UINavigationcontroller 中自动旋转 UIViecontroller 的问题

iphone - 如何识别 UITextFields 和键盘事件?

iOS8 区域本地化(例如 pt-BR)?

ios - 当我在搜索器上搜索某些内容时得到错误的索引