我创建了一个单视图测试应用程序并添加了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