我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。

具体来说:

是否有类似的功能,还是只有手动的方式?


当前回答

通过阅读stackoverflow上的许多线程,我发现解决方案是-

1.复制你的iPhone-Storyboard并重命名为MainStoryboard_iPad.storyboard

2.右击故事板->“打开为”->“源代码”。

3.搜索targetRuntime="iOS "。CocoaTouch,然后把它改成targetRuntime=" ios。CocoaTouch。ipad "

5.搜索<simulatedScreenMetrics key="destination" type="retina4"/>并将其更改为<simulatedScreenMetrics key="destination"/>

4.现在保存所有内容,右键单击MainStoryboard_iPad。storyboard " open as " ->"IOS storyboard " 5. 您可能还必须更改您的约束条件。 这就是你所做的一切。

其他回答

1 -创建“MainStoryboard_iPad.storyboard”;

2 -右键单击“MainStoryboard_iPhone.”故事板”和“打开作为->源代码”。所有复印件;

3-右键单击“MainStoryboard_iPad”。故事板”和“打开作为->源代码”。粘贴了一切。现在搜索和改变:

targetRuntime = " iOS。CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad" type = " com.apple.InterfaceBuilder3.CocoaTouch.Storyboard。" to type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.iPad.XIB"

4 -保存。现在重新打开,但是使用接口构建器。你只需要重新安排。

此方法也可用于.xib文件

只是为了好玩,在XCode 5.1和iOS 7.1上,我还需要改变“toolVersion”和“systemVersion”的值:

toolsVersion="5023" systemVersion="13A603"

如果没有这个,新的故事板文件将无法编译

这是另一种方式,但我能够做一个全选&复制在我的iPad故事板(~35个场景),并粘贴到我的iPhone故事板。场景大小自动调整。我只看到了两个问题,我必须替换UISplitViewController(因为它只是iPad),默认背景变成透明而不是灰色(仍在正确地修复这个问题,无需手动设置所有背景)。

编辑:在属性检查器中UITableView的默认背景似乎很奇怪。对于分组的表视图,我必须手动设置背景为“组表视图背景色”,对于非分组的表视图,我必须手动设置背景为“白色”。然后它被显示为“Default”(我假设它匹配了一个硬编码的值)。实际上,更简单的是,从“分组”切换到“静态”,然后再切换回来似乎会重置默认颜色。

1. Create New Storyboard file with MainStoryboard_iPad.storyboard
2. Copy All the views from MainStoryboard and paste to MainStoryboard_iPad.storyboard

There is a really simple solution for Xcode versions that support size classes (Tested in Xcode 7 which is the current version at the time of writing). Check the "use size classes" checkbox on a storyboard file (File Inspector), confirm that dialog that appears. Then uncheck that same checkbox - Xcode will ask you if you want to use this storyboard with an iPhone or iPad, and convert the screens in it appropriately. No need to directly edit the storyboard file. For both iPad and iPhone, just copy the same storyboard and configure one for iPad and one for iPhone using the described method.

在有人建议使用大小类之前——虽然很好,但对于重度定制的UI,比如游戏等,它们不太方便