如何在iOS 11中将导航栏设置为透明11

问题描述:

如何将导航栏设置为透明并在iOS 11中从普通透明到透明平滑过渡?如何在iOS 11中将导航栏设置为透明11

在iOS 11之前,我找到了_UIBarBackground视图并将其设置为alphaviewWillAppear:,并且在弹出,推送和向后滑动时它工作正常。

但是在iOS 11中,_UIBarBackground的alpha将自动在viewDidAppear后设置为1。

所以我很好奇,有没有其他完美的解决方案?

+0

你试过'uicolor.clearcolor'吗? –

  • 设置“为下视图控制器顶棒”在情节串连图板,这样你的视图将是下导航栏

  • 到视图添加子视图与帧{0,0,屏幕宽度,64},或使用自动布局约束。这种观点的

  • 设置背景色:

enter image description here

导航栏的设置背景透明:

- (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]; 
} 

现在你可以改变yelow以透明动画

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

+1

通过这种方式,我必须在每个视图控制器中添加这个视图,这不是一个简单的方式,我认为这并不安静。 –

+1

是的。但在这种情况下,您只使用公共API。用于创建导航栏透明的代码,您可以转移到uinavigationcontroller的类别。创建彩色标题视图的代码 - 在uiviewcontroller子类中。 – Josshad

+0

完美。这对我有用。 – Alexander