SmoothNavDemo
SmoothNavDemo copied to clipboard
iOS 10之前显示数组越界问题
在iOS 9.3 iPhone5 真机测试的时候,crash在[[barBackgroundView subviews] objectAtIndex:1],iOS 10 之前导航栏的subView和iOS10之后的有所不同,所以数组中只有一个imageView,显示数组越界; 本来想判断[barBackgroundView subviews]的个数防止越界,绕开了这个赋值操作,结果在第二次跳转的时候crash在了backgroundImageView.image,显示'unrecognized selector sent to instance ',最后只判断了是否存在backgroundImageView就设置透明度,目前iOS 10之前之后的版本都试了,真机也跑通了,就是想想下Cloudox,请问这个判断.image是否为空是否是刚需....可能目前只是没遇到这个bug,而已.
`- (void)setNeedsNavigationBackground:(CGFloat)alpha { // 导航栏背景透明度设置 UIView *barBackgroundView = [[self.navigationBar subviews] objectAtIndex:0];// _UIBarBackground UIImageView *backgroundImageView = (UIImageView *)[[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;
}`