簡體   English   中英

如何在iOS 11中將導航欄設置為透明

[英]How to set navigation bar to transparent in iOS 11

如何將導航欄設置為透明並在iOS 11中從正常過渡到透明?

在iOS 11之前,我找到_UIBarBackground視圖並在viewWillAppear:設置它的alpha ,並且在彈出,推送和向后滑動時它工作正常。

但是在iOS 11中, _UIBarBackground的alpha將在viewDidAppear之后自動設置為1。

所以我很奇怪,還有其他完美的解決方案嗎?

  • 在故事板中設置“視圖控制器的頂部欄”,以便您的視圖位於導航欄下方

  • 使用框架{0,0,screenWidth,64}將子視圖添加到視圖中,或者為其使用自動布局約束。

  • 設置該視圖的背景顏色:

在此輸入圖像描述

將導航欄的背景設置為透明:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [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];
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
}

現在,您可以使用動畫將黃色視圖更改為透明

示例項目: https//github.com/josshad/AnimatedNavBar

暫無
暫無

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

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