Skip to content

Commit

Permalink
Fixed Tencent#616 UITabBarItem (QMUI) qmui_imageViewInTabBarButton: c…
Browse files Browse the repository at this point in the history
…an not find the right UIImageView
  • Loading branch information
MoLice committed Jun 11, 2019
1 parent 646a953 commit e71f56a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions QMUIKit/UIKitExtensions/UITabBarItem+QMUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ + (UIImageView *)qmui_imageViewInTabBarButton:(UIView *)tabBarButton {
return nil;
}

for (UIView *subview in tabBarButton.subviews) {
// iOS10及以后,imageView都是用UITabBarSwappableImageView实现的,所以遇到这个class就直接拿
if ([NSStringFromClass([subview class]) isEqualToString:@"UITabBarSwappableImageView"]) {
return (UIImageView *)subview;
UIView *superview = tabBarButton;
if (@available(iOS 13.0, *)) {
if ([tabBarButton.subviews.firstObject isKindOfClass:[UIVisualEffectView class]]) {
// iOS 13 下如果 tabBar 是磨砂的,则每个 button 内部都会有一个磨砂,而磨砂再包裹了图片、label 等 subview
// https://github.com/Tencent/QMUI_iOS/issues/616
superview = ((UIVisualEffectView *)tabBarButton.subviews.firstObject).contentView;
}
}

for (UIView *subview in superview.subviews) {

if (IOS_VERSION < 10) {
// iOS10以前,选中的item的高亮是用UITabBarSelectionIndicatorView实现的,所以要屏蔽掉
if ([subview isKindOfClass:[UIImageView class]] && ![NSStringFromClass([subview class]) isEqualToString:@"UITabBarSelectionIndicatorView"]) {
if (@available(iOS 10.0, *)) {
// iOS10及以后,imageView都是用UITabBarSwappableImageView实现的,所以遇到这个class就直接拿
if ([NSStringFromClass([subview class]) isEqualToString:@"UITabBarSwappableImageView"]) {
return (UIImageView *)subview;
}
}

// iOS10以前,选中的item的高亮是用UITabBarSelectionIndicatorView实现的,所以要屏蔽掉
if ([subview isKindOfClass:[UIImageView class]] && ![NSStringFromClass([subview class]) isEqualToString:@"UITabBarSelectionIndicatorView"]) {
return (UIImageView *)subview;
}

}
return nil;
}
Expand Down

0 comments on commit e71f56a

Please sign in to comment.