0

私のアプリには、デバイスが正常に動作しているランドスケープモードのときに呼び出されるランドスケープビューコントローラーが1つあります。しかし、問題は、私がポートレートに戻って回転しているとき、それが台無しになることです。私は自分のアプリデリゲートでこれを行っています:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 

    [NSThread sleepForTimeInterval:1.5];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);


    // Override point for customization after application launch.
    UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;

    UIImage * logoImage = [UIImage imageNamed:NAVIGATION_LOGO_IMAGE];
    self.navController.navigationItem.titleView = [[UIImageView alloc] initWithImage:logoImage];
    self.navController.navigationItem.titleView.frame = CGRectMake(340,0 , 450, 55);

    // Create initialized instance of UITabBarController
    tabController = [[UITabBarController alloc] init];
    NSMutableArray *tabs = [[NSMutableArray alloc] init];
    // Create first UIViewController
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
    [viewController1 setTitle:@"Home"];
    navController = [[UINavigationController alloc] initWithRootViewController:viewController1];
    navController.navigationBar.tintColor = [UIColor blackColor];
    [tabs addObject:navController];

   viewController2 = [[TwitterDataLoad alloc] initWithNibName:@"TwitterDataLoad" bundle:nil];
     //viewController2 = [[TwitterDataController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
    [viewController2 setTitle:@"News"];
    navController = [[UINavigationController alloc] initWithRootViewController:viewController2];
     navController.navigationBar.tintColor = [UIColor blackColor];
    [tabs addObject:navController];

    viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    [viewController3 setTitle:@"Music"];
    navController = [[UINavigationController alloc] initWithRootViewController:viewController3];
     navController.navigationBar.tintColor = [UIColor blackColor];
    [tabs addObject:navController];

    viewController4 = [[ThumbNailViewController alloc] initWithNibName:@"ThumbNailViewController" bundle:nil];
    [viewController4 setTitle:@"Gallery"];
    navController = [[UINavigationController alloc] initWithRootViewController:viewController4];
     navController.navigationBar.tintColor = [UIColor blackColor];
    [tabs addObject:navController];

    viewController5 = [[FifthViewController alloc] initWithNibName:@"FifthViewController" bundle:nil];
    [viewController5 setTitle:@"Shows"];
    navController = [[UINavigationController alloc] initWithRootViewController:viewController5];
     navController.navigationBar.tintColor = [UIColor blackColor];
    [tabs addObject:navController];

    landscapeVC = [[LandscapeAboutViewController alloc] initWithNibName:@"LandscapeAboutViewController" bundle:nil];
    infamous = [[InfamousViewController alloc]initWithNibName:@"InfamousViewController" bundle:nil];
    NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

    if ( 5 == [[versionCompatibility objectAtIndex:0] intValue] ) 
    {
        [[UITabBar appearance]setTintColor:[UIColor blackColor]];
        [[UITabBar appearance]setSelectedImageTintColor:[UIColor whiteColor]];
    }
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    NSString * popUpShown = [defaults objectForKey:@"PopUpShown"];

    if (![popUpShown isEqualToString:@"yes"]) {

        [self showAlertView];
    }

    [tabController setViewControllers:tabs];

    self.window.rootViewController = tabController;
    [self.window makeKeyAndVisible];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didRotate:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];

    return YES;
}

- (void) didRotate:(NSNotification *)notification
{   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (UIDeviceOrientationIsLandscape(orientation)) {
        if (self.window.rootViewController != landscapeVC) {
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
            //[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationIsLandscape(orientation)];
            [self switchToLandScape];

        }

    }
    else if (UIDeviceOrientationIsPortrait(orientation)){
        if (self.window.rootViewController != tabController) {
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
            [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationIsPortrait(orientation)];

            [self switchToTabBar];

        }
    }
}

- (void)switchToTabBar {

    self.window.rootViewController = tabController;
}

- (void)switchToLandScape {

    self.window.rootViewController = landscapeVC;

}
4

2 に答える 2

0

UITabBarController をサブクラス化し、そのサブクラスに新しい iOS 6 ローテーション デリゲート メソッドを実装してみてください。次に、そのサブクラスをルート ビュー コントローラーとして使用して、iOS 6 での回転制御を向上させます。

于 2012-10-10T05:14:37.147 に答える
0

タブ バー コントローラーのサブクラスで、次のように指定します。

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

もう 1 つのオプションは、これをナビゲーション コントローラーのサブクラスに配置し、そのナビゲーション コントローラーにランドスケープ固有のビュー コントローラーを埋め込むことです。

于 2012-10-10T05:25:54.547 に答える