Ios UIViewContainement子控制器大小调整不正确

Ios UIViewContainement子控制器大小调整不正确,ios,uiviewcontroller,Ios,Uiviewcontroller,我正在iOS应用程序中使用UIViewContainess。在我的containerView中有一个contentView,我正在尝试在其中加载其他视图。如屏幕截图所示,子视图的大小不正确,因此加载很好 导航栏是容器的一部分 // load the new controller self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:menuItem.viewContr

我正在iOS应用程序中使用UIViewContainess。在我的containerView中有一个contentView,我正在尝试在其中加载其他视图。如屏幕截图所示,子视图的大小不正确,因此加载很好

导航栏是容器的一部分

  // load the new controller
    self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:menuItem.viewControllerStoryboardId];

    [self.containerView addSubview:self.contentViewController.view];
    [self.contentViewController didMoveToParentViewController:self];
    [self addChildViewController:self.contentViewController];

    self.title = menuItem.title;

下面是我用来在容器中加载childViewController的代码

  // load the new controller
    self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:menuItem.viewControllerStoryboardId];

    [self.containerView addSubview:self.contentViewController.view];
    [self.contentViewController didMoveToParentViewController:self];
    [self addChildViewController:self.contentViewController];

    self.title = menuItem.title;
以下似乎有效:

 self.contentViewController.view.frame = CGRectMake(0, 64, self.containerView.bounds.size.width, self.containerView.bounds.size.height);

只需尝试调整contentViewController视图的大小:

 self.contentViewController.view.frame = self.containerView.bounds;
 self.contentViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth
    | UIViewAutoresizingFlexibleHeight;

首先使用容器视图注释代码。现在它只是一个
ui视图
和其他视图一样。为其提供背景色或图像,以确保其位置和大小符合要求

如果不是(我猜不是),我也帮不了你很多,因为我不知道你是怎么做的。Struts和Spring、AutoLayout等。尝试自己修复,如果无法修复,请返回布局详细信息

假设它在形状和大小上都能正常工作。将包含的
UIViewController
添加回。这意味着此包含的视图控制器的
UIView
在其超级视图中的大小/位置不正确(
self.containerView

同样的过程。在
视图中显示
放置断点或日志记录,并检查其帧。您希望等待,直到所有视图都已通过布局,并且在您到达
viewdide出现时将发生这种情况


如果视图不是您期望的位置,请尝试找出它,如果无法找到,请返回并提供有关如何进行布局的更多详细信息。

谢谢!我只是这么做了,它没有改变任何事情。我的ChildViewController没有导航栏。我用适合我的可能答案编辑了我的问题!找到了问题!出于某种疯狂的原因,我让我的contentView一直跑到导航栏后面的顶部。我正确地调整了它,现在它工作了!