1

私は少し混乱しています。5 つの Viewcontrollers の 1 つだけでアプリを回転させたい。iOS 6 で回転するために必要なメソッドを実装する UINavigationcontroller のカテゴリを作成しました。

#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

また、回転しないすべての ViewControllers にこれらのメソッドを実装しました。

- (BOOL)shouldAutorotate {
    return NO;
}

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

ローテーションすべき人は shouldAutorotate で YES を返す

起動時に、追加の Viewcontroller を使用してスプラッシュスクリーンを表示します。この 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 の呼び出しだけが自動回転する必要があることですが、他の画面はそうではありません。ここでいくつかの必需品を逃した場合、誰か教えてもらえますか? iOS 6 で bl****y 自動回転を正しく動作させるために必要なことはすべてやったと思います...

前もって、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 に答える