Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Layout Not Appearing Right In Simulator or Real Device

I have a layout working fine in Xcode storyboard for a Master-Detail splitview app but when I run it in the Simulator or on an actual device it appears slightly messed up and I have no idea why.

The image in Xcode looks like this;

Xcode Looking Fine

The layout in Simulator and Device looks like this

Messed up image

like image 861
Flatlyn Avatar asked Jul 27 '12 01:07

Flatlyn


People also ask

How do I connect my real device to Xcode?

Plug in your device via USB​Open the Product menu from Xcode's menubar, then go to Destination. Look for and select your device from the list. Xcode will then register your device for development.

How do I refresh my Xcode simulator?

Selecting Reload (or pressing ⌘ + r in the iOS simulator) will reload the JavaScript that powers your application.

How do you refresh iPhone simulator?

If nothing above works out, then in Simulator menu , go to Devices and click on Restart . This restarts the device itself. Now go back to your terminal (where you're running expo) and press i (for ios simulator) and it should open up the app again.


1 Answers

This is almost certainly a problem with the autoresizing settings of your subviews (aka "Springs and Struts").

You are building a UISplitViewController-based application. Note that the dimensions of your Detail View Controller's frame are different when your app is running in portrait vs landscape mode. In your storyboard screenshot above you see the landscape-sized frame. The screen capture from your simulator shows the portrait-size frame. You'll need to set the struts and springs of your subviews (the UIPickerView, the brushed metal buttons, the white box below, etc) so that these elements resize (or not) and maintain their relative (or absolute) position in the parent view.

The easiest way to do this is to set the values in your storyboard, using the Size Inspector in the right column. Select which element you want to change settings for and then look for this:

enter image description here

By clicking on the red arrows inside the inner box you will toggle on/off the "springs", which determine whether your subview expands when the parent view expands, or whether it maintains its original size when that happens. By clicking on the outer red I-bars you will toggle on/off the "struts", which determine whether you subview will maintain a fixed distance from its parent view's edge when the parent view's size changes. Setting the right combination of these will make your view to look correct in both portrait and landscape orientations.

You can also change these settings programmatically in your code by setting the view's autoresizingMask property. See for reference:

http://developer.apple.com/library/ios/DOCUMENTATION/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW5

like image 79
jonkroll Avatar answered Oct 21 '22 07:10

jonkroll