在iOS6上旋转表现不同

Mar*_*cal 14 xcode autorotate ios autolayout

我做了一个基于标签的应用程序.没有什么需要在横向模式上,而是几个观点.它在iOS5上运行正常,我对结果非常满意.然而,对于iOS6而且没有任何混乱,它现在旋转所有视图,后果不太好.

因为它是一个基于选项卡的应用程序,我在横向上需要的几个视图是modalViews.这样我就没有搞乱tabbar,我只能在构建选项的"Supported Orientations"设置中选择portrait并设置:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

关于我想要的景观.

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

在所有视图中,我没有在故事板上选中"使用Autolayout"框.

这里有什么帮助?

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

iMa*_*euB 36

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

当用户更改设备方向时,系统会在根视图控制器或填充窗口的最顶层显示的视图控制器上调用此方法

为了让我的应用程序完全适用于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
Run Code Online (Sandbox Code Playgroud)

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];
Run Code Online (Sandbox Code Playgroud)

  • 自动轮换完全打破了我的iOS 6应用程序,这个修复工作完美.我只需要设置self.window.rootViewController(已经添加了子视图),我的旧iOS6前代码就可以了. (2认同)

Prc*_*ela 10

如果您使用标签栏控制器,这是iOS6的替代解决方案.它还表明不需要覆盖UINavigationController甚至UITabBarController.

在你的xyzAppDelegate.h中添加这个接口:

@interface UITabBarController (MyApp)
@end
Run Code Online (Sandbox Code Playgroud)

xyzAppDelegate.m中添加以下方法:

@implementation UITabBarController (MyApp) 

-(BOOL)shouldAutorotate
{
  return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
  // your custom logic for rotation of selected tab
  if (self.selectedIndex==...) {
    return UIInterfaceOrientationMaskAll;
  } 
  else {
    return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
  }
}

@end
Run Code Online (Sandbox Code Playgroud)

另外,为应用程序窗口设置根视图控制器:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  ...
  [self.window setRootViewController:tabBarController];
Run Code Online (Sandbox Code Playgroud)


Mik*_*e M 6

你在委托中设置rootViewController吗?例如,

    self.window.rootViewController = self.navigationController;
Run Code Online (Sandbox Code Playgroud)

当我做一些iOS6测试时,直到我这样做才能正常工作......


Luk*_*uke 5

我有一个很好的解决方案,交叉5.0到6.0工作 - 所有以上与

-(BOOL)shouldAutorotate{return [self shouldIRotateAnyiOS];}//iOS6

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return [self shouldIRotateAnyiOS];}//pre iOS6

-(BOOL)shouldIRotateAnyiOS{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
//do the rotation stuff
return YES
}
Run Code Online (Sandbox Code Playgroud)