Issues Starting in Landscape with IIViewDeckController as RootController on iPad

337 Views Asked by At

If I set a view deck controller as the AppDelegate window's root controller, when the app starts in landscape orientation on an iPad, the center view is displayed in it's Portrait orientation size and not resized to Landscape.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    IIViewDeckContoller *rootController = [IIViewDeckController new];

    self.window.rootViewController = rootController;
    self.window.backgroundColor = [UIColor blackColor];

    [self.window makeKeyAndVisible];
}

However, if I create a simple controller as a root controller, and then present the view deck controller from this root controller, then everything seems to display just fine.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *simpleRootController = [UIViewController new];
    IIViewDeckContoller *deckController = [IIViewDeckController new];

    self.window.rootViewController = simpleRootController;
    self.window.backgroundColor = [UIColor blackColor];

    [self.window makeKeyAndVisible];

     // View Deck Controller seems to have issues when it is the root controller of the main window.
    // Presenting it as a modal seems to do the trick.
    [simpleRootController presentViewController:self.deckController animated:NO completion:nil];
}

Anyone else run into this issue? Is there a better way to solve this? I do not see the same behavior with the iPhone.

1

There are 1 best solutions below

0
On

I've seen some people having success with the following method in IIViewDeckController:

- (CGRect) referenceBounds {
    if (self.referenceView) {
        return self.referenceView.bounds;
    }
    CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
        bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
    }
    return bounds;
}

However, I'm not seeing anything change. I can't take the OP's advice of presenting the view controller due to some other restrictions.