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 #3

Open
shengxiaolei opened this issue Jan 16, 2019 · 3 comments
Open

iOS12 好像获取不到self.navigationBar.subviews #3

shengxiaolei opened this issue Jan 16, 2019 · 3 comments

Comments

@shengxiaolei
Copy link

  • (void)setNavigationBackgroundAlpha:(CGFloat)navAlpha {
    CGFloat alpha = MAX(MIN(navAlpha, 1), 0);
    UIView *barBackground = self.navigationBar.subviews[0];
    UIView *colorView = [self getColorViewOnView:barBackground];
    colorView.alpha = alpha;
    if ([barBackground valueForKey:@"_shadowView"]) {
    UIView *shadowView = [barBackground valueForKey:@"_shadowView"];
    shadowView.alpha = alpha;
    shadowView.hidden = alpha == 0 ? YES : NO;
    }
    }

这个方法报错在iOS 12下

@koalahl
Copy link

koalahl commented Jun 12, 2019

改成 [[self.navigationBar subViews] firstObject] . 可以

@yimao009
Copy link

  • (void)setNavigationBackgroundAlpha:(CGFloat)navAlpha {
    CGFloat alpha = MAX(MIN(navAlpha, 1), 0);
    UIView *barBackground = self.navigationBar.subviews[0];
    UIView *colorView = [self getColorViewOnView:barBackground];
    colorView.alpha = alpha;
    if ([barBackground valueForKey:@"_shadowView"]) {
    UIView *shadowView = [barBackground valueForKey:@"_shadowView"];
    shadowView.alpha = alpha;
    shadowView.hidden = alpha == 0 ? YES : NO;
    }
    }

这个方法报错在iOS 12下

[0如果数组为空, 会发生奔溃, 使用firstObject会返回nil, oc里可以给nil发消息

@yimao009
Copy link

改成 [[self.navigationBar subViews] firstObject] . 可以

您好, iOS12和之前的系统在navgationbar上有什么更新变化吗, 为什么会导致这个bug呢?往指点

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