How to migrate from iPhone/iPad storyboards to universal storyboard

一曲冷凌霜 提交于 2019-12-21 09:17:08

问题


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.

Now I'm developing the same project in Xcode 6 and I want to use one universal storyboard instead of two storyboards. I have only worked on the iPhone storyboard and haven't touched the iPad one. Is it possible to ditch the iPad storyboard and convert the existing iPhone storyboard to be my main universal storyboard?


回答1:


I adapted this tutorial and a similar solution by @tharkay to create this solution below.

  • Rename Main_iPhone.storyboard to Main.storyboard
  • Delete 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. 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. Change targetRuntime from "iOS.CocoaTouch.iPad" to "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.

  • On Main.storyboard, on the right-hand panel choose the Show the File inspector icon.

  • Check the box named Use Size classes

  • XCode will prompt with an Xcode 5 compatibility message, Select YES.
  • Compile and run.
  • Of course, all your views should be messed up and you'll need to redo auto-layout.



回答2:


In xCode 9 I also had to add useTraitCollections="YES" property into document tag (same place where targetRuntime="iOS.CocoaTouch" is).




回答3:


I found a simple solution and it worked for me.

Duplicate your MainStoryboard and rename as MainStoryboard_iPad.storyboard from the File menu

Now Right click on your MainStoryboard_iPad file and click on open as a source code.

You will get an XML document. Now make some changes in XML file as below.

Search for targetRuntime="iOS.CocoaTouch" and change it to targetRuntime="iOS.CocoaTouch.iPad"

Remove The type = "retina4" as From <simulatedScreenMetrics key="destination" type="retina4"/> to

<simulatedScreenMetrics key="destination"/>

Again open the MainStoryboard_iPad file in interface builder. Hurray... You will get your iPad version storyboard. 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!



来源:https://stackoverflow.com/questions/26070572/how-to-migrate-from-iphone-ipad-storyboards-to-universal-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!