drc
drc

Reputation: 1915

What impact does simulated metrics have?

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?

Upvotes: 21

Views: 14983

Answers (3)

vacawama
vacawama

Reputation: 154691

The Simulated Metrics are 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].

I frequently set the Size to iPhone 4 inch because: 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 hR because the latter will actually affect which constraints are used for different sized devices.


[1] The Size and Orientation metrics 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.

[2] At the time Simulated Metrics were introduced, this was the way to 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.

Upvotes: 13

onmyway133
onmyway133

Reputation: 48175

Watch WWDC 2015 Session 407 Implementing UI Designs in Interface Builder, they talked about Simulated Metrics

enter image description here

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.

Upvotes: 6

Hugo
Hugo

Reputation: 2913

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.

Under the hood changing that size sets the rect value of the nib file as such:

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

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

Upvotes: 15

Related Questions