4

我正在尝试将两个故事板用于我的 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;

    }
}
4

1 回答 1

7

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

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

该按钮位于右下角 Zoom in % Zoom out 按钮的左侧,如下所示:

在此处输入图像描述

要处理对象的框架和位置如何受屏幕尺寸变化的影响——您需要为视图中的每个对象设置自动调整大小的属性。您可以通过选择一个对象来执行此操作,然后在右侧 Inspector 面板中,选择 Size 检查器,如下所示:

在此处输入图像描述

您看到 Autosizing 框中的那些红线了吗?与他们一起玩,看看他们将如何影响您的对象。内部的与大小有关(如果宽度或高度拉伸),外部的与位置有关。

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

你与每个人相处得越多,你就会越了解每个人的作用。

于 2013-01-10T21:03:45.147 回答