如何呈現UINavigationController
以使其呈現的視圖在背景中仍可見?半透明UINavigationController,以模態呈現
我的經驗是UINavigationController
會將任何東西都夾在其視圖之下,因此設置UINavigationController.view.alpha
將會發現固定的顏色背景,而不是呈現視圖的內容。
這可以改變嗎?
編輯
我不感興趣的導航欄,但完整的內容導航控制器管理。
如何呈現UINavigationController
以使其呈現的視圖在背景中仍可見?半透明UINavigationController,以模態呈現
我的經驗是UINavigationController
會將任何東西都夾在其視圖之下,因此設置UINavigationController.view.alpha
將會發現固定的顏色背景,而不是呈現視圖的內容。
這可以改變嗎?
編輯
我不感興趣的導航欄,但完整的內容導航控制器管理。
如果您希望這種行爲,您不能使用UINavigationController
,正如您所說的導航控制器剪輯內容控制器的視圖。要做你想做的事情,你應該添加一個導航條到你的視圖中,並且模擬導航控制器的動作。創建類似於控制器的後退按鈕this article
問題不在於UINavigationController,而在於您以模態方式呈現它。以模態方式呈現的ViewControllers永遠不會透明。
您可以通過將UINavigationControllers視圖添加爲主UIWindow的子視圖來僞造模態演示文稿。
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.35];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:viewController];
[[[[UIApplication sharedApplication] delegate] window] addSubview:navCon.view];
當然,你將不得不自己做任何動畫過渡,但應該使用動畫塊是微不足道的:
這個例子XCode中進行測試時,對我的作品。
然後你如何刪除它?我嘗試了[self.view removeFromSuperview]和[self.navigationController.view removeFromSuperview],但是你不能與原始視圖交互 – pathikrit
您的導航控制器在您呈現之後正在發佈。請記住,在UIWindow中將其視圖添加爲子視圖將僅保留導航控制器的視圖,而不是實際的導航控制器。所以你需要通過分配給伊娃,強大的財產或集合來保持它的活力。 –
現在有一種方法來實現這一目標使用iOS7定製的過渡,這樣一來:
MyController * controller = [MyController new];
[controller setTransitioningDelegate:self.transitionController];
controller.modalPresentationStyle = UIModalPresentationCustom;
[self controller animated:YES completion:nil];
創建自定義轉換,你需要兩件事情:
<UIViewControllerTransitionDelegate>
)<UIViewControllerAnimatedTransitioning>
)你可以找到在本教程中自定義過渡的更多信息:http://www.doubleencore.com/2013/09/ios-7-custom-transitions/
感謝。我想了解正在發生的事情以及爲什麼會發生這種情況,以及爲什麼不能在無法更改的情況下進行更改。 (我正在研究一個現有的項目,重寫navcontroller會太麻煩。) – ilmiacs