1

我有点困惑。我希望我的应用程序恰好在我的 5 个 Viewcontrollers 之一中旋转。我为 UINavigationcontroller 创建了一个类别,实现了在 ios 6 中旋转的必要方法。

#import "UINavigationController+IOS6Rotation.h"


@implementation UINavigationController (IOS6Rotation)

-(BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if (INTERFACE_IS_PAD) {
        return UIInterfaceOrientationLandscapeLeft;
    }
    else{
        return UIInterfaceOrientationPortrait;
    }    
}
@end

我还在所有不应该旋转的 ViewController 中实现了这些方法。

- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)supportedInterfaceOrientations {
    if (INTERFACE_IS_PAD) {
        return UIInterfaceOrientationMaskLandscape;
    }
    else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

应该旋转的那个在 shouldAutorotate 中返回 YES

在启动时,我使用额外的 Viewcontroller 来显示 Splashscreen。这个 SplashScreen 像这样显示为 RootViewController。

vc_splash = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenViewController" bundle:[NSBundle mainBundle]];
[self.window setRootViewController:vc_splash];

DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[self.window makeKeyAndVisible];  

当我完成加载我的数据库时,启动画面被交换为主屏幕。

self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: self.viewController];
    [self.window setRootViewController: navControl];

现在的问题是,只有我的 Splashscreen 调用 shouldAutorotate,但其他屏幕没有。有人可以告诉我我是否在这里遗漏了一些必需品吗?我以为我已经做了所有必要的事情来让 bl****y 自动旋转在 ios 6 中正常工作......

提前谢谢,Maverick1st

**更新* * 如果您希望 iPad 以横向模式启动,请务必在您的 shouldAutoRotate 中返回 YES,

4

1 回答 1

3

这对我有用添加supportedInterfaceOrientationsForWindow 方法application delegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
  [navigationController shouldAutorotate];
  [navigationController preferredInterfaceOrientationForPresentation];
  return UIInterfaceOrientationMaskAll;
}

还要添加这个application delegate

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
  return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
  return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
于 2012-11-16T12:43:26.843 回答