我有一个VIEW控制器,它通过loadView方法程序化地创建它的视图。视图的目的是显示数据模型的内容。加载视图时,它将在状态和导航栏下正确对齐。
但在稍后的一点上,我将提供另一个视图,允许用户选择不同的数据模型来填充视图。这将导致再次调用loadView并为新数据模型重新创建所需的ui。问题是视图的内容现在显示在状态栏和导航栏下!
请注意,由于必须支持ios4,所以我没有使用auto layout:(另外,如果我包含extendedLayout修复,它确实修复了问题,但只有在模态的dispose动画完成后,才会留下跳转效果。下面是我的代码,谢谢你的帮助。

- (void)loadView {

CGRect frame = CGRectMake(0, 0, [Constants ScreenWidth], [Constants ScreenHeight] - StatusBarHeight - ToolbarHeight);
self.view = [[UIView alloc] initWithFrame:frame];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;
self.view.backgroundColor = [Constants categoriesScreenBackgroundColor];

CGRect scrollFrame = CGRectMake(0, 0, [Constants ScreenWidth], [Constants ScreenHeight] - StatusBarHeight - ToolbarHeight - ToolbarHeight);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
        UIViewAutoresizingFlexibleBottomMargin |
        UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:scrollView];

_toolbarViewController = [self createToolbarViewController];
[self.view addSubview:_toolbarViewController.view];
_toolbarViewController.productInfoWorkflowState = _productInfoWorkflowState;

UIView *containerView = [[UIView alloc] initWithFrame:scrollView.frame];
containerView.backgroundColor = [UIColor clearColor];

_headerViewController = [self createHeaderViewController];
[containerView addSubview:_headerViewController.view];

_menuViewController = [[ProductInfoMenuViewController alloc] initWithBatch:[self batchData]];
_menuViewController.delegate = self;
[containerView addSubview:_menuViewController.view];

CGRect categoriesFrame = _menuViewController.view.frame;
categoriesFrame.origin.y = _headerViewController.view.frame.size.height;
_menuViewController.view.frame = categoriesFrame;

CGRect viewFrame = containerView.frame;
viewFrame.size.height = _headerViewController.view.frame.size.height + _menuViewController.view.frame.size.height;
containerView.frame = viewFrame;

[scrollView addSubview:containerView];
scrollView.contentSize = containerView.frame.size;

_starViewController = [[StarViewController alloc] initForProduct:_productData With:[StarredItems new]];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_starViewController.view];
}

首次加载后的屏幕布局:
二次加载后屏幕布局:
根据leo的建议,scrollview是正确的,但是底部的工具栏现在看起来不正确。我使用的代码(放在上面的工具栏创建代码之后):
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    self.automaticallyAdjustsScrollViewInsets = NO;
    scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(64.0f, 0.0f, 0.0f, 0.0f);
    scrollView.contentInset = UIEdgeInsetsMake(64.0f, 0.0f, 0.0f, 0.0f);
}

结果:

最佳答案

为同一问题添加以下代码对我有帮助

/* ios 7 Change */
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

08-26 10:15