Xcode storyboard: Why does the iPad storyboard sho

2019-01-21 17:29发布

I have a universal app that uses storyboards. There is an iPhone storyboard and an iPad storyboard. However, in interface builder, the viewcontrollers for the iPad storyboard are still sized for the iPhone. How do I get the iPad storyboard to show iPad sized view controllers?

I realize that the view controller display in interface builder is design-time-only eye-candy, but having iPhone sized VCs makes it really hard to lay out the UI correctly.

7条回答
混吃等死
2楼-- · 2019-01-21 17:57

I used the suggested answer to convert an iPhone storyboard to an iPad storyboard and it worked great for most of my views. However, I realized that one of the views was still iPhone storyboard sized. The reason was because I had locked All Properties of one background image (because I did not want to accidentally move it). Removing the lock turned the view back into iPad sized. This might help someone stuck on this.

查看更多
走好不送
3楼-- · 2019-01-21 17:57

Make sure you set the right Storyboard in Target > General. This kinda stuff makes me headache for 3 hours before i realise i set the same storyboard for iPhone as my iPad storyboard.

查看更多
小情绪 Triste *
4楼-- · 2019-01-21 18:03

When you first create a storyboard you select a Device Family (iPhone or iPad) that the storyboard is targeted for. I don't know of a way to change the device family once the storyboard has already been created.

However, to solve your problem I recommend the following:

Create a new storyboard by going to: New -> File -> User Interface -> Storyboard (Be sure to select Device Family = iPad when choosing the options.)

Go to your old storyboard, select and copy everything by pressing Command-A, Command-C. Then go to your and paste everything by pressing Command-V. Your view controllers will now be iPad-sized.

You can then delete the old storyboard and rename your new storyboard to whatever the old name was.

查看更多
地球回转人心会变
5楼-- · 2019-01-21 18:06

In my universal app, I was using SpriteKit for the main viewcontroller. The SKScene.scaleMode was set to aspectFill. When run in the iPad simulator, the app started up iPhone mode. Solution was to set scaleMode = .resizeFill.

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-21 18:07

After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?

The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:

  1. From Xcode, right-click on the storyboard and choose Open As -> Source code

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

  3. Right-click on the storyboard again and choose Open As -> iOS Storyboard

The storyboard will now show all views in the correct size.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-21 18:07

This answer is not a solution, but will help to get one of the reasons why such things happen.

The issue occurs when you try to disable:

"Use Auto Layout"

When you uncheck it, the popup window appears. There is select:

"Keep size class data for: iPhone", by default is selected iPhone (no matter which iPad or iPhone project you created).

If you will not mention on it, your storyboard will be auto converted to iPhone sizes.

Do not forget to choose right device.

查看更多
登录 后发表回答