Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
StephenQin opened this issue Dec 10, 2018 · 3 comments

Comments

@StephenQin
Copy link

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

@gleeeli
Copy link

gleeeli commented Dec 12, 2018

不维护了吗 哥们

@gleeeli
Copy link

gleeeli commented Dec 12, 2018

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

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

防止闪退

@LiShengP
Copy link

LiShengP commented Jun 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants