xcode 模拟指标有什么影响?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16279379/
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
What impact does simulated metrics have?
提问by drc
When using .xib files what impact on your code/app does changing simulated metrics have? Or is it just for your benefit as a preview tool?
使用 .xib 文件时,更改模拟指标对您的代码/应用程序有何影响?或者它只是为了您作为预览工具的利益?
采纳答案by vacawama
The Simulated Metricsare mostly a design aid to help you lay out your interface. They have little direct impact on the .xib*[1]. They are very helpful because you can simulate things like your view controller being imbedded in a navigation controller, which gives you less space to work with since the navigation bar takes up some space. They are also very handy if you are laying out a viewController that will only be used in landscape. At the time they were introduced, it was the only way to check how your interface would look on the shorter iPhone 4 display and the taller iPhone 5 display*[2].
该模拟指标大多设计援助,以帮助你躺在你的界面。它们对 .xib*[1] 几乎没有直接影响。它们非常有用,因为您可以模拟诸如嵌入在导航控制器中的视图控制器之类的东西,由于导航栏占用了一些空间,因此您可以使用更少的空间。如果您要布置一个仅用于横向的 viewController,它们也非常方便。在它们推出时,这是检查界面在较短的 iPhone 4 显示屏和较高的 iPhone 5 显示屏上的外观的唯一方法*[2]。
I frequently set the Sizeto iPhone 4 inchbecause: 1) I find working in the square viewController distracting, 2) It takes up much less screen real estate allowing me to see more of my Storyboard on my laptop display. This method is much less dangerous that changing the size class to wC hRbecause the latter will actually affect which constraints are used for different sized devices.
我经常将大小设置为iPhone 4 英寸,因为:1) 我发现在方形 viewController 中工作会分散注意力,2) 它占用更少的屏幕空间,让我可以在笔记本电脑显示器上看到更多的故事板。这种方法比将大小类更改为wC hR 的危险要小得多,因为后者实际上会影响对不同大小的设备使用哪些约束。
[1] The Sizeand Orientationmetrics will affect the size of the viewController as it is stored in the .xib
or .storyboard
file. If you leave the setting as Inferred, Xcode will use 600 x 600
as the viewController's size. Normally, this makes no difference, because the viewController will be properly sized to the device when it loads.
[1] Size和Orientation指标会影响 viewController 的大小,因为它存储在.xib
or.storyboard
文件中。如果您将设置保留为Inferred,Xcode 将600 x 600
用作 viewController 的大小。通常,这没有区别,因为 viewController 在加载时会根据设备正确调整大小。
[2] At the time Simulated Metricswere introduced, this was the wayto test designs for the iPhone 4s vs. the new taller iPhone 5. Apple has since introduced other better ways of checking out designs on various sized devices.
[2]在一次模拟指标进行了介绍,这是该方式来测试设计的iPhone 4S与新的更高的iPhone 5,苹果公司自从检查出各种尺寸的设备设计推出的其他更好的办法。
回答by Hugo
Well actually changing the Simulated Metrics does impact your application in a very sneaky way. I found that out while using the SwipeView library and my slides were all impacted by changing the Simulated Metric size.
实际上,更改模拟指标确实会以一种非常狡猾的方式影响您的应用程序。我在使用 SwipeView 库时发现了这一点,我的幻灯片都受到了更改模拟指标大小的影响。
Under the hood changing that size sets the rect value of the nib file as such:
在引擎盖下更改该大小将 nib 文件的 rect 值设置为:
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
That value is gonna be the size the nib launches. If we try to measure elements in view did load and view will appear we will have false information:
该值将是笔尖发射的大小。如果我们尝试测量视图中的元素确实加载并且视图将出现,我们将得到错误信息:
// viewDidLoad
(lldb) po splashImageView
<UIImageView: 0x79913eb0; frame = (0 0; 600 600); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x799ca310>>
// viewWillAppear
(lldb) po splashImageView
<UIImageView: 0x79913eb0; frame = (0 0; 600 600); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x799ca310>>
Once the layout subviews is done we do have the proper size but as far as SwipeView is concerned it's too late it already calculated the position of everything.
布局子视图完成后,我们确实有适当的大小,但就 SwipeView 而言,它已经计算了所有内容的位置为时已晚。
// viewDidLayoutSubviews
(lldb) po splashImageView
<UIImageView: 0x79913eb0; frame = (0 0; 768 1024); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x799ca310>>
If anyone can provide more information I'd really like it.
如果有人可以提供更多信息,我真的很喜欢。
回答by onmyway133
Watch WWDC 2015 Session 407 Implementing UI Designs in Interface Builder, they talked about Simulated Metrics
观看WWDC 2015 Session 407 在 Interface Builder 中实现 UI 设计,他们谈到了模拟指标
Inferred
推断
Now, right now they are all saying inferred. Inferred just basically means use the context around me. We know we are inside a tab bar controller, we know that we're inside a nav controller so interface builder knows which bar to show.
现在,现在他们都在说推断。推断只是基本上意味着使用我周围的上下文。我们知道我们在标签栏控制器内,我们知道我们在导航控制器内,因此界面构建器知道要显示哪个栏。
Simulated Metrics
模拟指标
All of these metrics do not affect your actual application at runtime with one exception and that's the size simulated metric.
The size simulated metric will actually change the size of your view controller but generally you're going to put it into a view controller hierarchy which will resize it, but it's also helpful if you are creating free form view controllers, for example, and want to set your own size.
所有这些指标都不会在运行时影响您的实际应用程序,只有一个例外,那就是大小模拟指标。
大小模拟指标实际上会改变你的视图控制器的大小,但通常你会把它放到一个视图控制器层次结构中,它会调整它的大小,但是如果你正在创建自由形式的视图控制器,例如,并且想要设置您自己的尺寸。