15

メソッドを使用してプログラムでビューを作成するView ControllerがありますloadView。ビューの目的は、データ モデルの内容を表示することです。ビューが読み込まれると、ステータス バーとナビゲーション バーの下に正しく配置されます。

しかし、後で別のビューをモーダルに表示して、ユーザーが別のデータ モデルを選択してビューに入力できるようにします。これにより、 がloadView再度呼び出され、新しいデータ モデルに必要な UI が再作成されます。問題は、ビューのコンテンツがステータス バーとナビゲーション バーの下に表示されることです。

iOS4をサポートする必要があるため、自動レイアウトを使用していないことに注意してください:(また、修正を含めるとextendedLayout、問題は修正されますが、モーダルの閉じるアニメーションが完了してジャンプダウン効果が残った後でのみです。以下の私のコード、ありがとうどんな助けでも。

- (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];
}

最初の読み込み後の画面レイアウト:

初回ロード後の画面レイアウト

2 回目の読み込み後の画面レイアウト:

2 回目の読み込み後の画面レイアウト

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);
}

結果:

ここに画像の説明を入力

4

6 に答える 6

14

次のコードを追加して、同じ問題のために私のために働きます。あなたの助けになるかもしれません

/* ios 7 Change */
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
于 2013-10-18T13:26:46.293 に答える
3

これは iOS 7 でのみ発生しますか?

これを試してください:

self.navigationController.navigationBar.translucent = NO;
于 2013-10-11T05:55:26.230 に答える
2

以下を試してください:

 Toolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
于 2013-10-13T23:42:38.283 に答える
1

これを試して

CGRect frame = CGRectMake(0, StatusBarHeight, [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, StatusBarHeight, [Constants ScreenWidth], [Constants ScreenHeight] - StatusBarHeight - ToolbarHeight - ToolbarHeight);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
        UIViewAutoresizingFlexibleBottomMargin |
        UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:scrollView];
于 2013-10-11T04:49:39.337 に答える