切换到横向时更改故事板

时间:2012-11-23 14:16:49

标签: xcode ipad orientation

当用户在AppDelegate.m文件中切换到横向模式时,有没有办法更改故事板我已经让它切换到不同iOS的不同StoryBoards但是我无法从横向切换到纵向模式我已经建立一个名为iPadios5landscape的故事板,我正在使用此方法切换到故事板mainStoryboard = [UIStoryboard storyboardWithName:@"iPadios5landscape" bundle:nil];但我不知道检测方向的方法。将它放在此代码中非常重要

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")==NO)
    {

            if (iOSDeviceScreenSize.height == 480)
            {

                mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_ios5" bundle:nil];
            }

            if (iOSDeviceScreenSize.height == 1024)
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if(orientation == 0) //Default orientation
        //UI is in Default (Portrait) -- this is really a just a failsafe.
        mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad_ios5" bundle:nil];

        else if(orientation == UIInterfaceOrientationPortrait)
            //Do something if the orientation is in Portrait
            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad_ios5" bundle:nil];

            else if(orientation == UIInterfaceOrientationLandscapeLeft)
                // Do something if Left
                mainStoryboard = [UIStoryboard storyboardWithName:@"iPadios5landscape" bundle:nil];

                else if(orientation == UIInterfaceOrientationLandscapeRight)
                    //Do something if right
                    mainStoryboard = [UIStoryboard storyboardWithName:@"iPadios5landscape" bundle:nil];

                    }

这可能吗?

1 个答案:

答案 0 :(得分:0)

将其粘贴在那里以检测方向,然后设置故事板,如果deviceOrientation是横向或纵向

 UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == 0) //Default orientation 
    //UI is in Default (Portrait) -- this is really a just a failsafe. 
 else if(orientation == UIInterfaceOrientationPortrait)
    //Do something if the orientation is in Portrait
else if(orientation == UIInterfaceOrientationLandscapeLeft)
    // Do something if Left
else if(orientation == UIInterfaceOrientationLandscapeRight)
    //Do something if right