【发布时间】:2012-12-05 13:18:52
【问题描述】:
我创建了一个单视图测试应用,并在主情节提要的UIViewController 中添加了UIButton 和UIView。我已经调整了按钮和视图的大小以具有相同的大小。
在我的 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 未选中“Autoresize Subviews”(尽管这两种方式都没有区别)。
(Xcode 4.5.2.iOS 6.0)
谢谢, 计算机科学
【问题讨论】:
-
从视图底部延伸出来的那条线,也许是让它自动调整视图大小?
-
jjv360:那一行只是 IB 的自动居中指南。它可以帮助您在其父视图中居中视图)。它与绘画无关。 :)
-
向视图添加内容并查看它是否自动调整大小。
-
Captain.MM - 我不知道为什么这会导致 same 应用程序在设备和模拟器上的行为不同,但我在小 UIView 中添加了一个 UILabel 和没有区别(正如预期的那样)。
-
您正在使用相当新的约束。可能存在错误并非不可能。尝试删除它们。
标签: ios xcode uiview ios-simulator bounds