2013-10-11 31 views
15

我有一個View Controller,它通過loadView方法以編程方式創建其視圖。該視圖的目的是顯示數據模型的內容。視圖加載時,它在狀態和導航欄下正確對齊。iOS7當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]; 
} 

屏幕布局:第二負載後

Screen layout after first load

屏幕布局:

Screen layout after second load

獅子座的修復建議,滾動視圖是正確的,但在底部的工具欄將出現錯誤。我使用的代碼(位於上方的工具欄中創建代碼後):

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

結果:

enter image description here

+0

請張貼期望和結果的屏幕截圖。 –

+0

從(總視圖高度 - 工具欄高度)設置工具欄的原點。 –

回答

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]; 
+0

這隻會讓事情變得更糟我很害怕:( – bennythemink

3

這是否僅在iOS 7發生的呢?

試試這個:

self.navigationController.navigationBar.translucent = NO; 
+0

沒有運氣我害怕,但感謝您的幫助:( – bennythemink

1

我認爲這個問題是由於不正確的自動設置了滾動的內容插圖的。

請嘗試以下操作。在您的loadView中,將self.automaticallyAdjustsScrollViewInsets設置爲NO(僅限於NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)。現在,設置contentInsetscrollIndicatorInsets到正確的值取決於操作系統版本:

scrollview.contentInset = scrollview.scrollIndicatorInsets = UIEdgeInsetMake(NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1 ? 0 : 64, 0, 0, 0); 
+0

這種作品,但導致另一個問題:(我已附加結果在我原來的屏幕截圖問題: – bennythemink

2

嘗試以下操作:

Toolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 
+0

它已經有這樣的設置我很害怕:( – bennythemink

14

添加以下代碼它陪伴了我同樣的問題的工作,可能是它的幫助你

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

沒有運氣,我害怕:(謝謝你的嘗試。 – bennythemink

+0

我做了這個loadView之前設置違規的看法,它的工作完美。 – DemonGyro

0

我的問題已解決,取消選中視圖控制器中的「調整滾動視圖插圖」(使用故事板)。