导航栏背景透明度设置
来源:互联网 发布:大数据魔方 编辑:程序博客网 时间:2024/05/22 18:24
(void)setNeedsNavigationBackground:(CGFloat)alpha {
// 导航栏背景透明度设置
UIView *barBackgroundView = [[self.navigationController.navigationBar subviews] objectAtIndex:0];// _UIBarBackground
UIImageView *backgroundImageView = [[barBackgroundView subviews] objectAtIndex:0];// UIImageView
if (self.navigationController.navigationBar.isTranslucent) {
if (backgroundImageView != nil && backgroundImageView.image != nil) {
barBackgroundView.alpha = alpha;
} else {
UIView *backgroundEffectView = [[barBackgroundView subviews] objectAtIndex:1];// UIVisualEffectView
if (backgroundEffectView != nil) {
backgroundEffectView.alpha = alpha;
}
}
} else {
barBackgroundView.alpha = alpha;
}// 对导航栏下面那条线做处理
self.navigationController.navigationBar.clipsToBounds = alpha == 0.0;
}