xcode 4.5 如何在发布时选择故事板 [英] xcode 4.5 how to pick storyboards at launch

查看:35
本文介绍了xcode 4.5 如何在发布时选择故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图让我的应用同时适用于 iPhone 5 和 iPhone 4/4s.我尝试了AutoLayout",但似乎对我的应用程序不起作用,还读到它在 iOS 5 中不受支持. AutoLayout 特别在具有 UIScrollview 和 UIPicker 的视图控制器上失败,该视图控制器在代码中重新调整了大小.有两个故事板,一个是 4 英寸,一个是 3.5 英寸,这似乎是可行的方法.

Trying to make my app work with both iPhone 5 and iPhone 4/4s. I tried the "AutoLayout" but does not seem to work for my app also read that it is not supported in iOS 5. AutoLayout specifically fails on a view controller that has an UIScrollview and a UIPicker that is re-sized in code. Having two Storyboards one for 4 inch and one for 3.5 inch seems the way to go.

两个 Storyboard aproch 似乎是我的解决方案.所以这给我留下了两个问题;

The two Storyboard aproch seem to be the solution for me. So this leaves me with two questions;

  1. 如果是 4/4s/5,要检测的代码应该去哪里?我假设在 appDelegate.m 中的 didFinishLaunchingWithOptions 方法

  1. Where should the code to detect then if it is a 4/4s/5 go? I would assume in the appDelegate.m in the didFinishLaunchingWithOptions method

如何更改主故事板"?

推荐答案

这是一个很好的问题.

你需要做的是,

  1. 选择您当前的 4/4 秒故事板,转到文件,复制,然后为其指定一个 iPhone 5 特定名称.确保选中 Target 和您的应用名称.

接下来,您必须在故事板中选择场景,然后在属性检查器中将大小更改为 Retina 4 Full Screen.这允许您重新排列此显示的所有内容.

Next you have to select the scenes in your storyboard and in the Attributes Inspector change the size to Retina 4 Full Screen. This allows you to rearrange everything for this display.

最后在应用程序 didFinishLaunchingWithOptions 中粘贴以下代码以及您为 4 英寸故事板指定的故事板名称.

Finally in application didFinishLaunchingWithOptions paste the following code with the storyboard name you gave for your 4 inch storyboard.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    UIStoryboard *storyBoard;

    CGSize result = [[UIScreen mainScreen] bounds].size;
    CGFloat scale = [UIScreen mainScreen].scale;
    result = CGSizeMake(result.width * scale, result.height * scale);

    if(result.height == 1136){
        storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
        UIViewController *initViewController = [storyBoard instantiateInitialViewController];
        [self.window setRootViewController:initViewController];
    }
}

return YES;
}

<小时>

如果有人不知道如何做第 1 步,请按以下步骤操作.

  1. 转到项目目录并复制粘贴MainStoryboard.storyboard 并将新故事板重命名为MainStoryboard5.storyboard.

  1. Go to Project directory and copy paste the MainStoryboard.storyboard and rename new storyboard to say MainStoryboard5.storyboard.

在项目(在 Xcode 中)中添加这个新的故事板 MainStoryboard5.storyboard,方法是右键单击 Project 并单击 Add Files to ....

Add this new storyboard MainStoryboard5.storyboard in project (in Xcode) by right clicking Project and clicking Add Files to ....

现在我们在 xcode 中有两个故事板.

Now we have two storyboards in xcode.

提示

在完成上述所有操作后,您可能必须使用产品 > 清洁"才能使其正常工作.

You may have to use 'Product > Clean' for this to work after you have done all the above.

这篇关于xcode 4.5 如何在发布时选择故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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