Xcode Storyboard 中的“Inferred”和“Freeform”有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32819768/
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-09-15 07:57:12  来源:igfitidea点击:

What is the difference between "Inferred" and "Freeform" in Xcode Storyboard?

iosxcodestoryboardxib

提问by Pradeep Reddy Kypa

I have a custom view which needs to be displayed on all the iPhone devices(4, 4S, 5, 5S, 6 and 6 Plus). When creating the custom view XIB, I have mentioned it as "Inferred" but it is not resizing for iPhone 6 and iPhone 6 Plus devices. I am not able to figure out the issue. I am confused on what would be actual differences between "Inferred" and "Freeform". Can someone please explain the differences?

我有一个自定义视图,需要在所有 iPhone 设备(4、4S、5、5S、6 和 6 Plus)上显示。在创建自定义视图 XIB 时,我将其称为“推断”,但它并未针对 iPhone 6 和 iPhone 6 Plus 设备调整大小。我无法弄清楚这个问题。我对“推断”和“自由形式”之间的实际差异感到困惑。有人可以解释这些差异吗?

回答by Robert J. Clegg

Inferredresizes the scene according to its parent scene. For example if you have a scene that is the size of an iPad and then you add a new scene to your storyboard and create a segue to it, it will automatically resize to the same size as the iPad scene (where the segue originates from).

Inferred根据其父场景调整场景的大小。例如,如果您有一个 iPad 大小的场景,然后将一个新场景添加到故事板并为其创建转场,它将自动调整为与 iPad 场景相同的大小(转场的来源) .

Freeformignores the above rule and you're able to size it as you see fit, in the utility pane on the right.

Freeform 会忽略上述规则,您可以在右侧的实用程序窗格中根据需要调整其大小。

Both of these however have nothing to do with how the view is displayed and sized on actual devices. For that you need to use auto layoutand constraints. Or springs and struts. Some even do it in code if they need more flexibility.

然而,这两者都与视图在实际设备上的显示方式和大小无关。为此,您需要使用auto layout和约束。或者springs and struts。如果他们需要更多的灵活性,有些人甚至会在代码中做到这一点。

回答by Nirzar Gandhi

“Inferred” is the default setting for storyboards and it means the scene will show a navigation bar when it's inside of a navigation controller, a tab bar when it's inside of a tab bar controller, and so on. You could override these settings if you wanted to, but keep in mind they are here only to help you design your screens. The Simulated Metrics aren't used during runtime, they're just a visual design aid that shows what your screen will end up looking like.

“推断”是情节提要的默认设置,这意味着场景将在导航控制器内部时显示导航栏,在标签栏控制器内部时将显示标签栏,等等。如果您愿意,您可以覆盖这些设置,但请记住,它们仅用于帮助您设计屏幕。模拟指标在运行时不使用,它们只是一种视觉设计辅助工具,用于显示您的屏幕最终会是什么样子。

"FreeForm" Usually you use the freeform property when you add the view controller as a child to another view controller programmatically and you really want to have that fixed size.If you push the view controller or you present it as modal view controller (and you use the modal presentation styles) then there is no need to use freeform.Also another use of the freeform property is to preview the actual size of your view controller when is presented as a modal view controller using existent presentation styles.

“FreeForm” 通常,当您以编程方式将视图控制器作为子视图控制器添加到另一个视图控制器时,您会使用自由格式属性,并且您确实希望拥有该固定大小。如果您推送视图控制器或将其呈现为模态视图控制器(并且您使用模态展示样式)那么就不需要使用自由形式了。另外,自由形式属性的另一个用途是在使用现有展示样式作为模态视图控制器呈现时预览视图控制器的实际大小。