2016-06-22 51 views
0

我有一個UINavigationController與3個viewControllers。我們知道三個viewController共享一個通用導航欄。如果我想設置navigationBar完全透明。我可以把代碼viewWillAppear顯示透明UINavigationbar將看到黑條時滑動viewController

[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
[self.navigationBar setShadowImage:[UIImage new]]; 
[self.navigationBar setBarTintColor:[UIColor clearColor]]; 
    self.navigationBar.translucent = YES; 

,並設置它放回viewWillDisappear

[self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 
[self setShadowImage:nil]; 
[self setBarTintColor:THEME_COLOR]; 
self.translucent = NO; 

我想設置UINavigationBar半透明僅在viewControllerB,所以我把代碼viewControllerB。但是,當我popToViewController B,我可以看到屏幕右上方的黑色欄。由於調用了viewWillAppear。這似乎不能解決我的情況。

我拿出一些方法:

  1. 使用不同UINavigationBar
  2. 使用不同的UINavigationController。但UINavigationController無法推送新的UINavigationController
  3. 自定義UIViewUINavigationBar

我覺得上面methos更爲複雜。

任何想法感謝!

+0

把你的代碼'ViewControllerB'和'ViewControllerC' –

+0

我不明白你的意思,「因爲'viewWillAppear'被調用,看起來不能解決我的情況。你能否以不同的方式重述?你可以在屏幕右上角添加黑條的圖像嗎?看起來很奇怪,你不會在屏幕的整個頂部看到橫條。 – Palpatim

回答

0

你看到的黑色是主窗口的背景色。您可以從AppDelegate didFinishLaunchingWithOptions方法(這完全取決於您對視圖控制器B的設計)將背景圖像或顏色設置爲主窗口,以便您看不到任何區別。

否則

只要您可以使用viewDidAppear,而不是使用viewWillAppear,但這樣做幾乎沒有甩尾,雖然。