1
我添加了一個視圖到[[UIApplication sharedApplication] keyWindow]
,因爲我們希望它重疊導航欄。如何在已添加到keyWindow的視圖上呈現模態?
現在我們要點擊視圖上的按鈕並打開窗口,最好使用presentViewController
。有沒有辦法讓這個模態視圖出現在keyWindow視圖的上方(在z軸上)?
我的回答
我結束了我的加入第一個自定義UIViewController
到self.tabBarController
。這允許UIViewController
重疊導航欄和選項卡欄。
然後我使用[self.navigationController presentViewController:animated:completion]
來呈現模態,它在z軸上高於其他所有模態。
這裏是添加UIViewController
到self.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];
對不起,你可以擴展一下嗎?當我查找諸如「導航控制器視圖」或「頂級子視圖」之類的術語時,我找不到任何信息。幾乎所有我在「導航欄」頂部放置'UIViewController'的發現,都說使用keyWindow。 http://stackoverflow.com/questions/21850436/add-a-uiview-above-all-even-the-navigation-bar – Chris
尋找到這個答案http://stackoverflow.com/a/24256824/300129 – Chris