如何在 iOS 11 中将导航栏设置为透明并从正常到透明平滑过渡?
在 iOS 11 之前,我找到了 _UIBarBackground
View 并在 viewWillAppear:
中将其设置为 alpha
,它在 pop、push 和向后滑动。
但在 iOS 11 中,_UIBarBackground
的 alpha 会在 viewDidAppear
后自动设置为 1。
所以我想知道,还有没有其他完美的解决方案?
最佳答案
在 Storyboard中设置“Under top bars for view controller”,这样您的 View 将位于导航栏下方
使用框架 {0,0,screenWidth,64} 将 subview 添加到您的 View ,或为其使用自动布局约束。
设置该 View 的背景颜色:
设置导航栏背景为透明:
- (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];
}
现在你可以通过动画将黄色 View 变为透明
关于ios - 如何在 iOS 11 中将导航栏设置为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46397231/