[英]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];
}
現在,您可以使用動畫將黃色視圖更改為透明
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.