Incorrect UIView bounds/drawing in the Simulator

懵懂的女人 提交于 2019-12-07 22:09:10

问题


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.

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


回答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".



来源:https://stackoverflow.com/questions/13724173/incorrect-uiview-bounds-drawing-in-the-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!