iOS iPhone 5选择正确的故事板 [英] iOS iPhone 5 Choose Correct Storyboard

查看:112
本文介绍了iOS iPhone 5选择正确的故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的iOS项目使用两个故事板,但我不能得到的代码切换到适当的故事板。相反,代码绝对没有什么。是不是我没有正确设置控制开关的设置?不是iPhone 5的设备的主要故事板被称为MainStoryboard。 iphone 5适当的布局称为iphone5。我认为这可能是一个项目配置设置问题。 (这在我的appdelegate.m文件中)。

I am attempting to use both storyboards for my iOS project, but I cannot get the code to switch to the appropriate storyboards. Instead, the code does absolutely nothing. Is it that I do not have a setting set correctly that controls the switch? The main storyboard for devices not of the iPhone 5, is called MainStoryboard. The iphone 5 appropriate layout is called iphone5. I'm thinking this may be a project configuration setting issue. (This is in my appdelegate.m file).

-(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;

    }
}


推荐答案

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

I suggest just using 1 storyboard for handling the iPhone 5 vs iPhone 3-4S screen sizes.

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

When your Storyboard is open, there is a button at the bottom that toggles between the 2 sizes-- you can see in real-time how things will look.

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

The button is to the left of the Zoom in % Zoom out buttons in the bottom right corner, and looks like this:

>

要处理你的对象的框架&位置将受到屏幕大小更改的影响 - 您需要为视图中的每个对象设置自动调整属性。您可以通过选择一个对象来执行此操作,然后在右侧检查器面板中选择大小检查器,如下所示:

To handle how your object's frame & position will be affected by the screen size change-- you need to set the autosizing properties for each object in your view. You can do this by selecting an object, and in the right Inspector panel, Select the Size inspector like so:

您会在自动调整框中看到那些红线吗?和他们一起玩,看看他们会如何影响你的对象。

You see those red lines in the Autosizing box? Play around with them to see how they will effect your object. The inner ones relate to the size (if the width, or height stretches), and the outer ones relate to the position.

我不确定您的应用程式版面配置但是根据经验,你可能不得不混淆内部垂直线(高度将如何改变)和底线(你想要留在底部附近)。

I'm not sure about your apps layout but from experience you will probably have to mess with the inner vertical line (how the height will change), and the bottom line (you want that to stay near the bottom).

你越乱越乱,你会看到每个人做什么。

The more you mess around with each the more you will see what each does.

这篇关于iOS iPhone 5选择正确的故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆