3

我的应用程序在设计时只考虑了 4 英寸显示屏。在 3.5 英寸的模拟器上运行时,应用程序会丢失 0.5 英寸。

那么,我的问题是,如何在 Xcode 5 中为不同的屏幕尺寸设置不同的故事板?

我知道在我可以使用以下代码之前:

-(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 *Main_iPhone2 = [UIStoryboard storyboardWithName:@"Main_iPhone3" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [Main_iPhone2 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 *Main_iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [Main_iPhone 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;

}

}

但是与 Xcode 5 的交易,以及我认为该代码不起作用的原因是,在您的项目中的“常规”下有一个部分,它将故事板建立为整个特定设备类型的主要部分。

所以,要么有一种不同的方式来完成整个单独的故事板,要么我对代码做错了。该代码被放置在我的应用程序委托中,所以不要认为我有什么问题。

4

2 回答 2

4

Xcode 5 中启用自动布局的情节提要

在 Xcode 5 - Storyboard 中找到这个控件。一直到左侧的按钮在整个 Storyboard 的 3.5 和 4 英寸视图之间切换。希望这是你需要的。

于 2013-09-19T08:36:53.740 回答
0

尝试根据您的控件和视图设置 AutoSizing 左、右、下、上位置,在此处输入图像描述

于 2013-09-19T08:28:31.737 回答