我有一个自定义 UIViewController,它创建一个 View ,其中包含顶部的操作栏(带有 4 个按钮的 View )、一个表格 View ,然后是表格 View 下方的另一个 View 。布局全部在代码中完成,不使用自动布局。 一切都在 iOS 7.0 和 7.0.2 的各种设备上完美运行,但在模拟器中, Controller 的 Root View 锚定在屏幕的右上角 (0,0),而不是导航栏下方。
我将在 viewDidAppear: 方法中强制中继,但这看起来像是一个黑客......
感谢您的见解
编辑:添加了图像。您可以看到突出显示的 UIView。正如 ManicMonkOnMac 提到的,UIView 位于工具栏下方(但这仅发生在模拟器中,在设备上, View 排列得很好) 在 Controller 上的loadView方法中,我在创建 View 时设置了框架:
- (void)loadView
{
// Our parent view controller will resize us appropriately. The size set
// here is a convenience for initial view layout.
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
但是这个框架后来被改变了。不过,不是通过我的代码,而是通过 UIkit 代码)
编辑2:添加了loadView方法主体
最佳答案
编辑:在经历了 WWDC 2013 的第 201 场 session 之后,我想我已经找到了解决方案。
在 iOS 7 中,您可以在 View Controller 上设置一个属性来指定是否希望 View 与导航栏重叠。
viewController.edgesForExtendedLayout = UIRectEdgeNone;//UIRectEdgeAll specifies that nav bars should overlap the view.
与 iOS 6 不同,iOS 7 中的导航栏位于 View 上方。
使用不包括导航栏的框架大小。
代码:
CGRect框架 = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y+self.navigationController.navigationBar.frame.size.height,self.view.frame.size.width, self.view.frame.size.height);
CustomView *view = [[CustomView alloc] initWithFrame:frame];
[self.view addSubview:view];
关于ios - 运行 iOS7 模拟器时 UIViewController View 大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19278531/