iphone - UIView 不尊重 UINavigationController 中 'loadView' 中的框架

标签 iphone objective-c cocoa-touch

我有以下代码片段:

- (void)loadView {
    self.view = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 20.0, 40.0, 40.0)];
    self.view.backgroundColor = [UIColor blackColor];
}

如果我在使用主视图 Controller 中的“基于 View 的应用程序”创建的项目中运行代码片段,一切都会按预期工作。但是,如果我在使用“基于导航的应用程序”创建的项目中运行它,标签将填充屏幕(不考虑尺寸)。如何修复在导航 Controller 中呈现的行为?谢谢!

最佳答案

导航 View Controller 会将 View Controller 的 View 调整为显示区域的大小,因此您描述的行为是正常的且是设计使然的。通常,我们在层次结构的顶部使用空的 UIView,并将 subview 放在里面,在您的例子中是 UILabel。

关于iphone - UIView 不尊重 UINavigationController 中 'loadView' 中的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4176647/

相关文章:

iphone - 区分 iPhone 3G 和 iPhone 3GS

iPhone使用ASIHTTPRequest下载带有变量的图像

ios - 使用 Core Data 从 NSMutableArray 创建对象的 NSString

ios - 无法从 Quickblox 检索用户

objective-c - 如何在回调 block 中异步创建 FetchRequest

ios - 按钮在手机上不显示,但在 XCode 模拟器上显示

iphone - AVCaptureVideoPreviewLayer : taking a snapshot

ios - 您将如何以及在何处使用 instantiateViewControllerWithIdentifier

ios - 嵌入自定义容器 View Controller 时,内容位于导航栏下方。

iphone - 在模拟器上的钥匙串(keychain)中保存密码