Incorrect UIView bounds/drawing in the Simulator

2019-05-26 04:49发布

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

1条回答
2楼-- · 2019-05-26 05:46

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

查看更多
登录 后发表回答