簡體   English   中英

iOS 8 - 將模糊應用於導航欄和狀態欄

[英]iOS 8 — Apply blur to navigation bar AND status bar

我正在嘗試將模糊效果添加到導航欄和狀態欄。 我的問題是導航欄上的模糊很好,但狀態欄不會模糊。

我的問題是:如何擴展邊界以包含狀態欄?

我正在使用以下方法來創建模糊效果:

- (void) addBlurEffect {

CGRect bounds = self.navigationController.navigationBar.bounds;
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
visualEffectView.frame = bounds;
visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.navigationController.navigationBar addSubview:visualEffectView];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar sendSubviewToBack:visualEffectView];

}

在我的plist中,我有基於View控制器的狀態欄外觀YES

在viewDidLoad中我調用一個方法:

- (void)configureView {

    // style controls

    self.addAirportButton.tintColor = [UIColor whiteColor];

    // style background image

    UIImageView *sidebarBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebarBackground"]];
    self.tableView.backgroundView = sidebarBackground;

    // style navigation bar

    self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;

    // this makes navigation bar transparent

    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;

    // style toolbar

    self.navigationController.toolbar.translucent = YES;
    self.dismissAdsButton.tintColor = [UIColor whiteColor];

在viewDidLoad中完成其他任何重要操作。 當我構建它時,這是視圖的樣子 - 它是一個嵌入在NavigationController中的tableViewController,我也使用了優秀的SWRevealViewController。

查看狀態欄是如何模糊的:

模糊僅在導航欄部分 - 狀態欄不模糊

任何幫助將非常感激!

更新:

見下面的答案。 以下是已實施解決方案的屏幕截圖:

應用解決方案的屏幕截

我一直試圖取得類似的效果,在使用UINavigationBar的API進行調整后無法達到預期的效果后,我找到了一個解決方法:

  1. 創建一個與NavigationBar + StatusBar大小相同的UIView。 也就是說,它的幀數為(0,0,w,64),其中w是屏幕的寬度。 (我是通過Storyboard完成的,並使用autolayout將寬度約束設置為等於其superview的寬度約束)

  2. 設置UIView的backgroundColor來清除顏色。

  3. 使用以下代碼使navigationBar完全透明: navBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) navBar.shadowImage = UIImage() navBar.translucent = true

  4. 現在將模糊效果應用於該視圖,這會產生模糊效果來自導航欄和狀態欄的錯覺。

看到這張圖片是為了達到效果(抱歉,由於聲譽限制,我無法發布圖片)。

希望這可以幫助。

更新2015-05-28:

這就是我在StoryBoard中實現上述方法的方法:

  1. 在最頂層中創建導航欄背景視圖作為主視圖的直接子項。 請注意,我將其他所有內容都包含在一個內容視圖中。 內容視圖為紅色,導航欄背景視圖為半透明白色。

在此輸入圖像描述

  1. 在導航欄背景視圖上添加以下4個約束:0表示左,右和上限制,64表示高度約束。

暫無
暫無

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

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