简体   繁体   English

如何从iPhone / iPad故事板迁移到通用故事板

[英]How to migrate from iPhone/iPad storyboards to universal storyboard

I have a project created in Xcode 5. The "Deployment Info" settings says Devices: Universal but has separate iPhone and iPad settings and corresponding iPhone and iPad storyboards. 我在Xcode 5中创建了一个项目。“部署信息”设置显示设备:通用,但具有单独的iPhone和iPad设置以及相应的iPhone和iPad故事板。

Now I'm developing the same project in Xcode 6 and I want to use one universal storyboard instead of two storyboards. 现在我正在Xcode 6中开发相同的项目,我想使用一个通用故事板而不是两个故事板。 I have only worked on the iPhone storyboard and haven't touched the iPad one. 我只是在iPhone故事板上工作,并没有触及iPad。 Is it possible to ditch the iPad storyboard and convert the existing iPhone storyboard to be my main universal storyboard? 是否有可能放弃iPad故事板并将现有的iPhone故事板转换为我的主要通用故事板?

I adapted this tutorial and a similar solution by @tharkay to create this solution below. 我调整了本教程和@tharkay的类似解决方案 ,以便在下面创建此解决方案。

  • Rename Main_iPhone.storyboard to Main.storyboard Main_iPhone.storyboard重命名为Main.storyboard
  • Delete Main_iPad.storyboard 删除Main_iPad.storyboard
  • ***If you want to use the iPad storyboard instead of the iPhone, rename the Main_iPad.storyboard to Main.storyboard and delete the Main_iPhone.storyboard file. ***如果要使用iPad故事板而不是iPhone,请将Main_iPad.storyboard重命名为Main.storyboard并删除Main_iPhone.storyboard文件。 You will then need to go to the File Inspector and right-click your storyboard, then select “Open as Source Code”. 然后,您需要转到文件检查器并右键单击故事板,然后选择“作为源代码打开”。 This will display all that XML code. 这将显示所有XML代码。 Change targetRuntime from "iOS.CocoaTouch.iPad" to "iOS.CocoaTouch" targetRuntime"iOS.CocoaTouch.iPad"更改为"iOS.CocoaTouch"

From: 从:

targetRuntime="iOS.CocoaTouch.iPad" 

to: 至:

targetRuntime="iOS.CocoaTouch"
  • In the project file, under general settings, select Main.storyboard for both iPhone and iPad. 在项目文件中,在常规设置下,为iPhone和iPad选择Main.storyboard

在此输入图像描述

  • On Main.storyboard , on the right-hand panel choose the Show the File inspector icon. Main.storyboard上的右侧面板上,选择“ Show the File inspector图标。

在此输入图像描述

  • Check the box named Use Size classes 选中名为“ Use Size classes的框

在此输入图像描述

  • XCode will prompt with an Xcode 5 compatibility message, Select YES. XCode将提示Xcode 5兼容性消息,选择YES。
  • Compile and run. 编译并运行。
  • Of course, all your views should be messed up and you'll need to redo auto-layout. 当然,你的所有观点都应该搞砸了,你需要重做自动布局。

在xCode 9中,我还必须将useTraitCollections="YES"属性添加到文档标记中( targetRuntime="iOS.CocoaTouch"所在的相同位置)。

I found a simple solution and it worked for me. 我找到了一个简单的解决方案,它对我有用。

Duplicate your MainStoryboard and rename as MainStoryboard_iPad.storyboard from the File menu 复制MainStoryboard并从“ File菜单重命名为MainStoryboard_iPad.storyboard

Now Right click on your MainStoryboard_iPad file and click on open as a source code . 现在右键单击MainStoryboard_iPad文件,然后单击open as a source code

You will get an XML document. 您将获得一个XML文档。 Now make some changes in XML file as below. 现在在XML文件中进行一些更改,如下所示。

Search for targetRuntime="iOS.CocoaTouch" and change it to targetRuntime="iOS.CocoaTouch.iPad" 搜索targetRuntime="iOS.CocoaTouch"并将其更改为targetRuntime="iOS.CocoaTouch.iPad"

Remove The type = "retina4" as From <simulatedScreenMetrics key="destination" type="retina4"/> to 除去的类型= "retina4"作为从<simulatedScreenMetrics key="destination" type="retina4"/>

<simulatedScreenMetrics key="destination"/>

Again open the MainStoryboard_iPad file in interface builder. 再次在界面构建器中打开MainStoryboard_iPad文件。 Hurray... You will get your iPad version storyboard. 华友世纪......你将获得你的iPad版故事板。 Now you just need to change the width and height as per your Layout. 现在您只需根据布局更改宽度和高度。

This helped me alot and saved alot time. 这帮了我很多,节省了很多时间。

:) Im sure it will help you! :)我相信它会帮助你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM