SmoothNavDemo icon indicating copy to clipboard operation
SmoothNavDemo copied to clipboard

iOS12 运行不了上来就崩溃,数组越界,[[self.navigationBar subviews] objectAtIndex:0]; 为什么self.navigationBar subviews 一个控件都没有,做了什么操作么?

Open StephenQin opened this issue 6 years ago • 3 comments

iOS12 运行不了上来就崩溃,数组越界,[[self.navigationBar subviews] objectAtIndex:0]; 为什么self.navigationBar subviews 一个控件都没有,做了什么操作么?

StephenQin avatar Dec 10 '18 02:12 StephenQin

不维护了吗 哥们

gleeeli avatar Dec 12 '18 01:12 gleeeli

// 设置导航栏背景透明度

  • (void)setNeedsNavigationBackground:(CGFloat)alpha { // 导航栏背景透明度设置 if ([[self.navigationBar subviews] count] == 0) { return; } UIView *barBackgroundView = [[self.navigationBar subviews] objectAtIndex:0];// _UIBarBackground UIImageView *backgroundImageView = [[barBackgroundView subviews] objectAtIndex:0];// UIImageView if (self.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.navigationBar.clipsToBounds = alpha == 0.0; }

防止闪退

gleeeli avatar Dec 12 '18 01:12 gleeeli

这样用 在不同的系统上 很容易崩溃啊

LiShengP avatar Jun 09 '20 08:06 LiShengP