2014-09-13 19 views
1

在iOS 7中,導航欄對於在下面滾動的內容具有模糊效果。我想我的導航欄是透明的,這是實現這樣的:透明導航欄,但保持iOS模糊

[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault]; 
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
[[UINavigationBar appearance] setShadowImage:[UIImage new]]; 
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]]; 

但我希望內容也模糊。我嘗試了以下運氣:

[[UINavigationBar appearance] setBarTintColor:[UIColor clearColor]]; 
     [[UINavigationBar appearance] setBarStyle:UIBarStyleDefault]; 
     [[UINavigationBar appearance] setShadowImage:[UIImage new]]; 
     [[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]]; 

相反,這會使導航欄模糊內容視圖,但是是黑色的。如果我刪除了setBarTintColor,導航欄會模糊內容,但它是白色的。我嘗試了各種其他組合,但導航欄不是白色就是黑色。

我看過幾個SO問題,但他們不幫我。他們回答如何得到一個completely transparent navbarget a certain colour,當我想要的是它是清晰/透明的,沒有任何一種顏色色調

我該怎麼做到這一點?感謝您的幫助,非常感謝!

回答

0

讓它半透明。

繼承它,並添加代碼 -

- (id)initWithRootViewController:(UIViewController *)rootViewController 
{ 
    if (self = [super initWithRootViewController:rootViewController]) { 
     self.navigationBar.translucent = YES; 
    } 
    return self; 
} 
0

試試這個,它是基於工具欄的模糊透明,你還可以添加一些顏色到酒吧: 這個解決方案有你需要的iOS7支持

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] 
               forBarMetrics:UIBarMetricsDefault]; 
self.navigationController.navigationBar.shadowImage = [UIImage new]; 
self.navigationController.navigationBar.translucent = YES; 
self.navigationController.view.backgroundColor = [UIColor clearColor]; 
UIToolbar* blurredView = [[UIToolbar alloc] initWithFrame:self.navigationController.navigationBar.bounds]; 
[blurredView setBarStyle:UIBarStyleBlack]; 
[self.navigationController.navigationBar insertSubview:blurredView atIndex:0];