[英]How to set navigation bar to transparent in iOS 11
How to set navigation bar to transparent and get smooth transition from normal to transparent in iOS 11? 如何将导航栏设置为透明并在iOS 11中从正常过渡到透明?
before iOS 11, I find the _UIBarBackground
view and set it's alpha
in viewWillAppear:
, and it worked fine when pop, push and swipe back. 在iOS 11之前,我找到
_UIBarBackground
视图并在viewWillAppear:
设置它的alpha
,并且在弹出,推送和向后滑动时它工作正常。
But in iOS 11, _UIBarBackground
's alpha will be set to 1 after viewDidAppear
automatically. 但是在iOS 11中,
_UIBarBackground
的alpha将在viewDidAppear
之后自动设置为1。
So I'm wonder, is there any other perfect solutions? 所以我很奇怪,还有其他完美的解决方案吗?
Set 'Under top bars for view controller' in storyboard, so your view will be under navigation bar 在故事板中设置“视图控制器的顶部栏”,以便您的视图位于导航栏下方
Add subview to your view with frame {0,0,screenWidth,64}, or use auto layout constraints for it. 使用框架{0,0,screenWidth,64}将子视图添加到视图中,或者为其使用自动布局约束。
Set background color of that view: 设置该视图的背景颜色:
Set background of navbar to transparent: 将导航栏的背景设置为透明:
- (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];
}
Now you can change yelow view to transparent with animation 现在,您可以使用动画将黄色视图更改为透明
Example project: https://github.com/josshad/AnimatedNavBar 示例项目: https : //github.com/josshad/AnimatedNavBar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.