Converting Storyboard from iPhone to iPad

2019-01-01 12:00发布

I have an iPhone application which has a storyboard. Now I want to provide an iPad application too. So I asked me whether there is a function which helps me convert my iPhone storyboard to an iPad storyboard.

To be specific:

Is there a similar function or is there only the manual way ?

21条回答
人气声优
2楼-- · 2019-01-01 12:23

I followed this thread when I was hit with the same issue yesterday. The steps I followed

  1. For Xcode 5.1, I had to do some cleanup of iPhone storyboard like missing reuseIdentifiers of Table cells, provide story board id for every controller, remove unused scenes.
  2. Copy MainStoryboard_iPhone.storyboard to MainStoryboard_iPad.storyboard.
  3. Using vi editor - changed targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
  4. Change the code in the MainStoryboard_iPad.storyboard from: <simulatedScreenMetrics key="destination" type="retina4"/> to <simulatedScreenMetrics key="destination"/>
  5. Open the project in Xcode.
  6. Changed the Deployment devices to Universal - Chose the option of NOT copying the iPhone Storyboard.
  7. Xcode will default the Deployment Target to 7.1, took care of the deprecated functions.
  8. To fix the misplaced view error in iPad Storyboard - Changed the Frame Layout for Controllers giving errors.

That was it.. Thanks all for your help..

查看更多
长期被迫恋爱
3楼-- · 2019-01-01 12:25

From reading many threads on stackoverflow i discovered the solution is-

1.Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard

2.right click on the storyboard -> “open as” -> “Source Code”.

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

5.Search for <simulatedScreenMetrics key="destination" type="retina4"/> and change it to to <simulatedScreenMetrics key="destination"/>

4.Now save everything and right click on MainStoryboard_iPad.storyboard “open as” ->"IOS StoryBoard" 5. you may also have to change your constraints. Thats all you have done.

查看更多
人气声优
4楼-- · 2019-01-01 12:27

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.

And Before someone suggest to use size classes - while great, they are less convenient for heavily customized UI, such as games etc

查看更多
登录 后发表回答