2016-03-07 61 views
1

我添加了一個視圖到[[UIApplication sharedApplication] keyWindow],因爲我們希望它重疊導航欄。如何在已添加到keyWindow的視圖上呈現模態?

現在我們要點擊視圖上的按鈕並打開窗口,最好使用presentViewController。有沒有辦法讓這個模態視圖出現在keyWindow視圖的上方(在z軸上)?

我的回答

我結束了我的加入第一個自定義UIViewControllerself.tabBarController。這允許UIViewController重疊導航欄和選項卡欄。

然後我使用[self.navigationController presentViewController:animated:completion]來呈現模態,它在z軸上高於其他所有模態。

這裏是添加UIViewControllerself.tabBarController

 MyCustomViewController * overlayView = [[MyCustomViewController alloc] 
         initWithNibName:@"MyCustom" 
         bundle:nil]; 

     UIViewController *parentViewController = self.tabBarController; 
     [modalView willMoveToParentViewController:parentViewController]; 

     // set the frame for the overlayView 
     overlayView.view.frame = parentViewController.view.frame; 

     [parentViewController.view addSubview: overlayView.view]; 

     [parentViewController.view needsUpdateConstraints]; 
     [parentViewController.view layoutIfNeeded]; 

     // Finish adding the overlayView as a Child View Controller 
     [parentViewController addChildViewController: overlayView]; 
     [overlayView didMoveToParentViewController:parentViewController]; 

回答

0

你應該反思一下,你將疊加層視圖方式的代碼。

如果您希望視圖重疊導航欄,您可以將此視圖添加爲導航欄的頂層子視圖。或者您可以將其添加爲導航控制器視圖的頂層子視圖。

+0

對不起,你可以擴展一下嗎?當我查找諸如「導航控制器視圖」或「頂級子視圖」之類的術語時,我找不到任何信息。幾乎所有我在「導航欄」頂部放置'UIViewController'的發現,都說使用keyWindow。 http://stackoverflow.com/questions/21850436/add-a-uiview-above-all-even-the-navigation-bar – Chris

+0

尋找到這個答案http://stackoverflow.com/a/24256824/300129 – Chris

相關問題