iphone - UIViewController 或 UINavigationController 是否设置其 View 的大小?

标签 iphone ios uiview uiviewcontroller uinavigationcontroller

我有几个 UIViewController,通过 UINavigationController 加载,我在其中覆盖 loadView,并设置要显示的自定义 View 。我在设置某些 subview 的框架时遇到问题,也许还有 View 本身。我认为 UINavigationController 或 UIViewController 能够强制其 View 在显示时填满屏幕。

我想知道是否和/或何时设置 View 的大小。如果发生这种情况,是设置 View 的框架,还是以其他方式进行。

谢谢。

更新: 我刚刚注意到,在完成此工作时,我使用此 loadView 方法创建了一个新的 UINavigationController:

- (void)loadView
{
  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 10.0f, 10.0f)];
  [view setBackgroundColor:[UIColor redColor]];
  self.view = view;
  [view release];
}

我看到一个红色 View 占据了整个屏幕,除了状态栏和标题。我的 View 何时调整大小以填满屏幕?创建 View 时我应该使用什么尺寸?

最佳答案

UINavigationController 将在按下时自动调整 ViewController 的 View 大小。来自文档:

pushViewController:animated:

The object in the viewController parameter becomes the top view controller on the navigation stack. Pushing a view controller results in the display of the view it manages. How that view is displayed is determined by the animated parameter. If the animated parameter is YES, the view is animated into position; otherwise, the view is simply displayed in place. The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.

如果您想要显示较小的 View ,则必须创建一个容器并将其作为 VC View 的 subview ,手动设置大小。可能必须正确设置自动调整大小掩码,具体取决于您创建 View 的方式。

关于iphone - UIViewController 或 UINavigationController 是否设置其 View 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7812933/

相关文章:

objective-c - Google Analytics 不适用于 Swift 1.2 和 Xcode 6.3

ios - 如何解决swift 3中标签中最后一个值的重叠问题

swift - NavigationBar 和 StatusBar 上方的 UIView

iphone - 如何使 iAd 集成 iPhone 应用程序在以前版本的 iPhone 操作系统上运行?

iphone - iPhone 中的通知

ios - 操作无法完成。 (com.facebook.sdk 错误 5.)当尝试使用 ID 获取详细信息时

iphone - 从整个应用程序目录的 zip 文件安装 iPhone 应用程序

iPhone 调整 subview 和原点的大小

iPhone 向左 curl 和向右 curl 过渡

ios - 文件 “MyProgramm.ipa” 无法打开,因为没有该文件