OGeek|极客世界-中国程序员成长平台

标题: iphone - 在一个 View Controller 中强制纵向使其他 View Controller 最初处于纵向 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:10
标题: iphone - 在一个 View Controller 中强制纵向使其他 View Controller 最初处于纵向

导航 Controller 的 Root View Controller 仅支持纵向,其他 Controller 支持所有方向。现在,如果我在 Root View Controller 上并且设备处于横向,并且如果我插入下一个以纵向打开的 View Controller 应该打开在横向,因为它支持所有方向。

请帮我解决这个问题。

使用 iPhone 4s iOS6.1.3



Best Answer-推荐答案


您可以在登录 View Controller 后使用以下代码在您的第一个屏幕中检查设备方向:-

-(void)viewWillAppearBOOL)animated
    {
        [self willRotateToOrientation:[[UIDevice currentDevice] orientation]];  
        [super viewWillAppear:YES];
    }


- (void)willRotateToOrientationUIInterfaceOrientation)newOrientation {
        if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        {
            if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {

              //set your landscap View Frame
                [self supportedInterfaceOrientations];

            }



        }
        else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        {
            if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
      //set your Potrait View Frame
                [self supportedInterfaceOrientations];

            }
        }
        // Handle rotation
    }

当您加载此 View Controller 时,它会首先检查设备方向,然后加载它的相关帧

关于iphone - 在一个 View Controller 中强制纵向使其他 View Controller 最初处于纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16710899/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4