模拟器中的 UIView 边界/绘图不正确

2024-04-08

我创建了一个单视图测试应用程序并添加了UIButton and UIView to the UIViewController在主故事板中。我已将按钮和视图的大小调整为相同的大小。

在我的 VC 的 -viewDidAppear:animated 方法中,我转储按钮和视图的框架和边界:

- (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));
}

这是在模拟器中运行时的输出:

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

在设备上运行时:

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

我不明白为什么在模拟器中运行时视图报告的高度为 12。视图在模拟器中绘制不正确,但在设备上运行时按预期绘制。请注意,UIViewController是最上面的UIVIew未选中“自动调整子视图大小”(尽管这两种方式都没有什么区别)。

(Xcode 4.5.2。iOS 6.0)

谢谢, CS


单击显示布局中的“应用 Retina 4 外形规格”按钮。您已针对 Retina 4 设置了此设置,因此在模拟器中运行时屏幕大小会调整为 3.5。您可以通过运行iPhone5模拟器(Retina 4英寸)来验证这一点。将外形尺寸切换为 3.5 英寸后,您会注意到高度更改为 12。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

模拟器中的 UIView 边界/绘图不正确 的相关文章

随机推荐