2

如果我将视图平台控制器设置为 AppDelegate 窗口的根控制器,则当应用程序在 iPad 上以横向启动时,中心视图将以其纵向大小显示,而不是调整为横向大小。

- (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];
}

但是,如果我创建一个简单的控制器作为根控制器,然后从这个根控制器呈现视图甲板控制器,那么一切似乎都显示得很好。

- (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];
}

还有其他人遇到这个问题吗?有没有更好的方法来解决这个问题?我没有看到与 iPhone 相同的行为。

4

1 回答 1

0

我见过一些人在 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;
}

但是,我没有看到任何变化。由于其他一些限制,我无法接受 OP 关于呈现视图控制器的建议。

于 2014-05-30T22:16:47.380 回答