0

我现在正在为 Ipad 测试一个应用程序。基本上我正在使用模板进行主详细信息应用程序并有另一个 PortraitViewController。现在,当应用程序以纵向模式启动时,我希望它仅显示 PortraitViewController,而当设备旋转时,例如横向模式,我希望仅显示 master-detailViewController。做这个的最好方式是什么。

我正在测试单视图应用程序的示例代码,但主从视图拒绝隐藏:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view = self.portrait;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform =
        CGAffineTransformMakeRotation(degreesToRadians(0));
        self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform =
        CGAffineTransformMakeRotation(degreesToRadians(−90));
        self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
    }
    else if (interfaceOrientation ==
             UIInterfaceOrientationLandscapeRight) {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform =
        CGAffineTransformMakeRotation(degreesToRadians(90));
        self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
} } 
4

1 回答 1

1

视图控制器不应该像这样实时更改其视图。您没有看到任何事情发生,因为视图控制器的旧视图仍在界面中;您不会将其从界面中删除。你也不应该这样做。实现这一点的方法是更换视图控制器;使用不同的视图控制器和不同的视图。

您从主从视图控制器开始,因此应用程序的根视图控制器是 UISplitViewController。它的视图(拆分视图),它出现,是您要删除的视图。因此,您必须将 UISplitViewController 替换为窗口的rootViewController.

但这是一个巨大的痛苦。我认为在纵向放置时,将模态(呈现的)视图控制器放在所有东西的前面可能会更快乐。

这是一个可下载的示例项目,它呈现一个视图控制器以响应设备旋转:

https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch19p609rotationForcingModalView

于 2013-03-27T00:48:16.217 回答