Skip to content

Commit

Permalink
Fixed Tencent#616 删除 UITabBarItem (QMUI) qmui_imageViewInTabBarButton…
Browse files Browse the repository at this point in the history
… 方法,请使用 qmui_imageView 代替
  • Loading branch information
MoLice committed Jun 17, 2019
1 parent 9d00dc0 commit d610aca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.m
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ - (void)layoutSubviews {
CGPoint centerOffset = IS_LANDSCAPE ? self.qmui_updatesIndicatorView.centerOffsetLandscape : self.qmui_updatesIndicatorView.centerOffset;

UIView *superview = self.qmui_updatesIndicatorView.superview;
if ([NSStringFromClass(superview.class) hasPrefix:@"UITabBar"]) {
if ([self isKindOfClass:[UITabBarItem class]]) {
// 特别的,对于 UITabBarItem,将 imageView 的 center 作为参考点
UIView *imageView = [UITabBarItem qmui_imageViewInTabBarButton:superview];
UIView *imageView = ((UITabBarItem *)self).qmui_imageView;
if (!imageView) return;

self.qmui_updatesIndicatorView.frame = CGRectSetXY(self.qmui_updatesIndicatorView.frame, CGRectGetMinXHorizontallyCenter(imageView.frame, self.qmui_updatesIndicatorView.frame) + centerOffset.x, CGRectGetMinYVerticallyCenter(imageView.frame, self.qmui_updatesIndicatorView.frame) + centerOffset.y);
Expand All @@ -376,9 +376,9 @@ - (void)layoutSubviews {
CGPoint centerOffset = IS_LANDSCAPE ? self.qmui_badgeLabel.centerOffsetLandscape : self.qmui_badgeLabel.centerOffset;

UIView *superview = self.qmui_badgeLabel.superview;
if ([NSStringFromClass(superview.class) hasPrefix:@"UITabBar"]) {
if ([self isKindOfClass:[UITabBarItem class]]) {
// 特别的,对于 UITabBarItem,将 imageView 的 center 作为参考点
UIView *imageView = [UITabBarItem qmui_imageViewInTabBarButton:superview];
UIView *imageView = ((UITabBarItem *)self).qmui_imageView;
if (!imageView) return;

self.qmui_badgeLabel.frame = CGRectSetXY(self.qmui_badgeLabel.frame, CGRectGetMinXHorizontallyCenter(imageView.frame, self.qmui_badgeLabel.frame) + centerOffset.x, CGRectGetMinYVerticallyCenter(imageView.frame, self.qmui_badgeLabel.frame) + centerOffset.y);
Expand Down
2 changes: 0 additions & 2 deletions QMUIKit/UIKitExtensions/UITabBarItem+QMUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@
*/
- (UIImageView *)qmui_imageView;

+ (UIImageView *)qmui_imageViewInTabBarButton:(UIView *)tabBarButton;

@end
4 changes: 2 additions & 2 deletions QMUIKit/UIKitExtensions/UITabBarItem+QMUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ + (UIImageView *)qmui_imageViewInTabBarButton:(UIView *)tabBarButton {

UIView *superview = tabBarButton;
if (@available(iOS 13.0, *)) {
if ([tabBarButton.subviews.firstObject isKindOfClass:[UIVisualEffectView class]]) {
// iOS 13 下如果 tabBar 是磨砂的,则每个 button 内部都会有一个磨砂,而磨砂再包裹了图片、label 等 subview
if ([tabBarButton.subviews.firstObject isKindOfClass:[UIVisualEffectView class]] && ((UIVisualEffectView *)tabBarButton.subviews.firstObject).contentView.subviews.count) {
// iOS 13 下如果 tabBar 是磨砂的,则每个 button 内部都会有一个磨砂,而磨砂再包裹了 imageView、label 等 subview,但某些时机后系统又会把 imageView、label 挪出来放到 button 上,所以这里做个保护
// https://github.com/Tencent/QMUI_iOS/issues/616
superview = ((UIVisualEffectView *)tabBarButton.subviews.firstObject).contentView;
}
Expand Down

0 comments on commit d610aca

Please sign in to comment.