ios Xcode 故事板:为什么 iPad 故事板显示 iPhone 大小的视图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9877113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:32:36  来源:igfitidea点击:

Xcode storyboard: Why does the iPad storyboard show iPhone sized views?

iosxcodeinterface-builderstoryboard

提问by memmons

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?

我有一个使用故事板的通用应用程序。有一个 iPhone 故事板和一个 iPad 故事板。但是,在界面构建器中,iPad 故事板的视图控制器的大小仍然适用于 iPhone。如何让 iPad 故事板显示 iPad 大小的视图控制器?

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.

我意识到界面构建器中的视图控制器显示是设计时唯一的眼睛糖果,但是拥有 iPhone 大小的 VC 使得正确布局 UI 变得非常困难。

回答by memmons

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?

在对故事板源代码进行了一些挖掘之后,发现 iPad 故事板是从 iPhone 故事板复制而来的。所以,问题真的变成了如何将 iPhone 故事板转换为 iPad 故事板?

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

答案出奇的简单。我遇到了这个 SO 答案——要将 iPhone 故事板转换为 iPad 故事板,请执行以下操作

  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

  1. 在 Xcode 中,右键单击情节提要并选择打开为 -> 源代码

  2. 搜索targetRuntime="iOS.CocoaTouch"并将其更改为targetRuntime="iOS.CocoaTouch.iPad"

  3. 再次右键单击情节提要并选择打开为 -> iOS 情节提要

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

故事板现在将以正确的大小显示所有视图。

回答by jonkroll

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.

首次创建情节提要时,请选择情节提要针对的设备系列(iPhone 或 iPad)。一旦故事板已经创建,我不知道有什么方法可以更改设备系列。

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.)

创建一个新的故事板:新建 -> 文件 -> 用户界面 -> 故事板(选择选项时一定要选择设备系列 = iPad。)

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.

转到您的旧故事板,按 Command-A、Command-C 选择并复制所有内容。然后按 Command-V 转到您的并粘贴所有内容。您的视图控制器现在将是 iPad 大小的。

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

然后,您可以删除旧故事板并将新故事板重命名为旧名称。

回答by Nazir

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).

"Keep size class data for: iPhone",默认选择iPhone(无论您创建的是哪个 iPad 或 iPhone 项目)。

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

如果您不提及它,您的故事板将自动转换为iPhone 尺寸

Do not forget to choose right device.

不要忘记选择正确的设备。

回答by neoneye

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

在我的通用应用程序中,我使用 SpriteKit 作为主视图控制器。将SKScene.scaleMode被设置为aspectFill。在 iPad 模拟器中运行时,应用程序启动 iPhone 模式。解决方案是设置scaleMode = .resizeFill.

回答by Andrew

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.

我使用建议的答案将 iPhone 故事板转换为 iPad 故事板,它适用于我的大多数观点。但是,我意识到其中一个视图仍然是 iPhone 故事板大小。原因是因为我锁定了一张背景图片的所有属性(因为我不想不小心移动它)。解除锁定将视图恢复为 iPad 大小。这可能会帮助有人坚持这一点。

回答by mfnugraha

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.

确保在 Target > General 中设置了正确的 Storyboard。这种东西让我头痛了 3 个小时,然后我才意识到我为 iPhone 设置了与 iPad 故事板相同的故事板。

回答by RikMaxSpeed

Changing the targetRunTime didn't work for me in Xcode 6.2, however this 2nd method of manually copying over the views did the trick.

在 Xcode 6.2 中更改 targetRunTime 对我不起作用,但是手动复制视图的第二种方法可以解决问题。