簡體   English   中英

透明的導航欄,但保持iOS模糊

[英]Transparent Navigation Bar but Keep iOS Blur

在iOS 7中,導航欄對在下面滾動的內容具有模糊效果。 我希望我的導航欄是透明的,可以這樣實現:

[[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問題,但它們對我沒有幫助。 他們回答如何獲得完全透明的導航欄獲得某種顏色 ,而我想要的是它是透明/透明的, 而沒有任何顏色

我將如何實現? 感謝您的幫助,不勝感激!

使它透明。

子類化,並添加代碼-

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

嘗試此操作,它基於ToolBar的模糊透明度,您也可以為該Bar添加一些顏色:此解決方案很好,因為您需要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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM