【问题标题】:Switch between Master-Detail View and other view controllers on rotation?在主从视图和其他视图控制器之间切换?
【发布时间】:2013-03-27 00:38:04
【问题描述】:

我现在正在为 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);
} } 

【问题讨论】:

    标签: ios ipad ios6


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多