2

I've created a single-view test app and added a UIButton and UIView to the UIViewController in the main storyboard. I have resized both the button an view to have the same size.

enter image description here

In my VC's -viewDidAppear:animated method I dump the frame and bounds of the button and view:

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"button bounds: %@", NSStringFromCGRect(self.theButton.bounds));
    NSLog(@"button frame:  %@", NSStringFromCGRect(self.theButton.frame));

    NSLog(@"view bounds:   %@", NSStringFromCGRect(self.theView.bounds));
    NSLog(@"view frame:    %@", NSStringFromCGRect(self.theView.frame));
}

And here is the output when running in the simulator:

button bounds: {{0, 0},     {100, 100}}
button frame:  {{110, 72},  {100, 100}}
view bounds:   {{0, 0},     {100, 12}}
view frame:    {{110, 179}, {100, 12}}

When run on a device:

button bounds: {{0, 0},     {100, 100}}
button frame:  {{110, 72},  {100, 100}}
view bounds:   {{0, 0},     {100, 100}}
view frame:    {{110, 179}, {100, 100}}

I do not understand why the view reports a height of 12 when running in the simulator. The view is drawn incorrectly in the simulator but draws as expected when run on a device. Note that the UIViewController's topmost UIVIew has "Autoresize Subviews" unchecked (although it doesn't make a difference either way).

(Xcode 4.5.2. iOS 6.0)

Thanks, CS

enter image description here

RobertJoseph
  • 7,968
  • 12
  • 68
  • 113
  • That line extending from the bottom of the view, maybe that's making it auto resize the view? – jjv360 Dec 05 '12 at 13:28
  • jjv360: That line is just IB's auto-centering guide. It helps you center a view in its parent view). It has nothing to do with drawing. :) – RobertJoseph Dec 05 '12 at 13:34
  • Add content to the view and see if it auto-resizes. – Mark McCorkle Dec 05 '12 at 13:56
  • Captain.MM - I have no idea why that would cause the *same* app to behave differently on a device and the simulator, but I added a UILabel to the small UIView and it makes no difference (as expected). – RobertJoseph Dec 05 '12 at 14:15
  • You are using constraints, which are fairly new. It is not unlikely that there could be bugs. Try removing them. – Adam Lockhart Dec 05 '12 at 14:30
  • I have been struggling with the same type of problem for a couple of days now (deeply frustrating as I tend to suspect my auto layout setup and not potential bugs). Do you know more about this issue today? Can I be sure that once shipped, the app will have a correct layout on both screen sizes? (I'm using Xcode 5.1) – Lukas Kalinski Apr 07 '14 at 21:48
  • I have now submitted a bug report on this (16545466). – Lukas Kalinski Apr 07 '14 at 22:33

1 Answers1

1

Click the "Apply Retina 4 Form Factor" button in the display layout. You have this set for Retina 4 so the screen is resizing for 3.5 when running in the simulator. You can verify this by running the iPhone5 simulator (Retina 4 inch). You will notice the height changes to 12 after toggling the form factor to 3.5".

enter image description here

Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • Thanks MarkM. That was indeed my problem. I'm wondering how I *should* be working in IB then. For example, say I want the view to be 100, 100 regardless of the device/simulator size? And why didn't the button resize the way the view did? (Again, thanks in advance) – RobertJoseph Dec 05 '12 at 15:08
  • I tend to ALWAYS use the 3.5" form factor then toggle back and forth to check compatibility. This alleviates having to fire up the simulator every time to check layouts. AutoLayout has added another layer to this but the concept is the same. Stick with the 3.5" layout unless you don't plan on supporting any 3.5" devices. Ray has a pretty good article about this on his site. To be completely honest, I still prefer not using the AutoLayout feature. http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2 – Mark McCorkle Dec 05 '12 at 15:23
  • Again, thank you Mark - I now understand the issue and will move forward using your suggestions. I will also checkout Ray's tutorial (I love that site). Please upvote my question unless you think I am an idiot. ;-) – RobertJoseph Dec 05 '12 at 15:35
  • Can I upvote even if I think you're an idiot?!?! LOL, totally joking... upvoted. ;-) And yes, Ray has been a great start for many devs throughout the years. The many authors on there have written great tuts and offer excellent real world examples. – Mark McCorkle Dec 05 '12 at 15:38