iOS iPhone 5选择正确的故事板

Kli*_*tel 4 iphone cocoa-touch objective-c storyboard ios

我正在尝试将两个故事板用于我的iOS项目,但我无法让代码切换到相应的故事板.相反,代码绝对没有.是否我没有正确设置控制开关的设置?不属于iPhone 5的设备的主要故事板称为MainStoryboard.iphone 5适当的布局称为iphone5.我想这可能是项目配置设置问题.(这是在我的appdelegate.m文件中).

-(void)initializeStoryBoardBasedOnScreenSize {

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    {    // The iOS device = iPhone or iPod Touch


        CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

        if (iOSDeviceScreenSize.height == 480)
        {   // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)

            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
            UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

            // Instantiate the initial view controller object from the storyboard
            UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];

            // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

            // Set the initial view controller to be the root view controller of the window object
            self.window.rootViewController  = initialViewController;

            // Set the window object to be the key window and show it
            [self.window makeKeyAndVisible];
        }

        if (iOSDeviceScreenSize.height == 568)
        {   // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)

            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
            UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iphone5" bundle:nil];

            // Instantiate the initial view controller object from the storyboard
            UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];

            // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

            // Set the initial view controller to be the root view controller of the window object
            self.window.rootViewController  = initialViewController;

            // Set the window object to be the key window and show it
            [self.window makeKeyAndVisible];
        }

    } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)

    {   // The iOS device = iPad

        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;

    }
}
Run Code Online (Sandbox Code Playgroud)

Rya*_*anG 7

我建议只使用1个故事板来处理iPhone 5和iPhone 3-4S屏幕尺寸.

当您的故事板打开时,底部有一个按钮可以在两种尺寸之间切换 - 您可以实时查看事物的外观.

该按钮位于右下角的"放大%缩小"按钮的左侧,如下所示:

在此输入图像描述

要处理屏幕大小更改会影响对象框架和位置的方式,您需要为视图中的每个对象设置自动调整大小属性.您可以通过选择一个对象来执行此操作,并在右侧的"检查器"面板中,选择"大小"检查器,如下所示:

在此输入图像描述

您是否在自动调整框中看到了这些红线?和他们一起玩,看他们将如何影响你的对象.内部的大小(如果宽度或高度伸展),外部的大小与位置有关.

我不确定你的应用程序布局,但根据经验你可能不得不弄乱内部垂直线(高度将如何改变)和底线(你希望它保持在底部附近).

你越乱越乱,你会看到每个人做的越多.