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

UITabBar layout is broken on iOS 12.1 #410

Closed
ziecho opened this issue Oct 11, 2018 · 20 comments

Comments

Projects
None yet
10 participants
@ziecho
Copy link
Collaborator

commented Oct 11, 2018

请填写运行环境

  • 设备:iPhone X、 iPhone 7 puls
  • 系统:iOS 12.1
  • Xcode 版本:10.0
  • QMUI iOS 版本:2.8.1

请描述具体问题

QMUI Demo 注释掉配置 tabBarBackgroundImage 后可复现:

//    QMUICMI.tabBarBackgroundImage = [[UIImage qmui_imageWithColor:UIColorMake(249, 249, 249)] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];                     // TabBarBackgroundImage : UITabBar 的背景图

相关截图(断点的堆栈、控制台的 log)

image

@wyt666

This comment has been minimized.

Copy link

commented Oct 13, 2018

这是iOS12.1系统的问题

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Oct 15, 2018

待 12.1 正式版发布后再看这个问题是否还存在

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Oct 24, 2018

实测这个问题是 iOS 12.1 Beta 2 的问题,只要 UITabBar 是磨砂的,并且 push viewController 时 hidesBottomBarWhenPushed = YES 则手势返回的时候就会触发。

出现这个现象的直接原因是 tabBar 内的按钮 UITabBarButton 被设置了错误的 frame,frame.size 变为 (0, 0) 导致的。

如果需要,可以使用以下临时修补代码,待发布的 QMUI 新版里也会带上这部分代码,等到 iOS 12.1 正式版发布后如果这个问题被修复,我们也会把这段代码移除。

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (@available(iOS 12.1, *)) {
            OverrideImplementation(NSClassFromString(@"UITabBarButton"), @selector(setFrame:), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP originIMP) {
                return ^(UIView *selfObject, CGRect firstArgv) {
                    
                    if ([selfObject isKindOfClass:originClass]) {
                        // 如果发现即将要设置一个 size 为空的 frame,则屏蔽掉本次设置
                        if (!CGRectIsEmpty(selfObject.frame) && CGRectIsEmpty(firstArgv)) {
                            return;
                        }
                    }
                    
                    // call super
                    void (*originSelectorIMP)(id, SEL, CGRect);
                    originSelectorIMP = (void (*)(id, SEL, CGRect))originIMP;
                    originSelectorIMP(selfObject, originCMD, firstArgv);
                };
            });
        }
    });
}
@wyt666

This comment has been minimized.

Copy link

commented Oct 24, 2018

如果这个问题没有被修复的话,在UITabBar 的- (void)layoutSubviews 方法中重新给UITabBarButton设置frame也可以解决这个问题

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Oct 24, 2018

如果这个问题没有被修复的话,在UITabBar 的- (void)layoutSubviews 方法中重新给UITabBarButton设置frame也可以解决这个问题

@wyt666 那就需要自己去计算 button 的 frame,那样不是很合理。

@wyt666

This comment has been minimized.

Copy link

commented Oct 24, 2018

恩,临时解决一下,等着被苹果修复

@xiaoxiongke

This comment has been minimized.

Copy link

commented Oct 26, 2018

赞一下~~:)

@MoLice MoLice changed the title iOS 12.1 pop 手势返回过程中 Tabbar 图标位置异常 UITabBar layout is broken on iOS 12.1 beta Oct 26, 2018

@ziecho

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 31, 2018

实测 iOS 12.1 正式版还未修复此 BUG

@zhaoquntao

This comment has been minimized.

Copy link

commented Oct 31, 2018

iOS 12正式版并没有修复 这个bug

@814349837

This comment has been minimized.

Copy link

commented Oct 31, 2018

iOS 12.1 正式版 bug依然存在

@bawn

This comment has been minimized.

Copy link

commented Oct 31, 2018

@MoLice MoLice changed the title UITabBar layout is broken on iOS 12.1 beta UITabBar layout is broken on iOS 12.1 Oct 31, 2018

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Nov 1, 2018

2.9.0 已带上这个修复。

@dingchuandong

This comment has been minimized.

Copy link

commented Nov 8, 2018

用上面的方法
iPhone X tabbar还是会出现一定的下移的呢
其他设备可以

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Nov 8, 2018

@dingchuandong 你说的是#422 吧?那是另一个问题,与这个无关。

@dingchuandong

This comment has been minimized.

Copy link

commented Nov 9, 2018

嗯 是滴 我在特殊处理下 感谢

@fujianjin6471

This comment has been minimized.

Copy link

commented Nov 19, 2018

实测这个问题是 iOS 12.1 Beta 2 的问题,只要 UITabBar 是磨砂的,并且 push viewController 时 hidesBottomBarWhenPushed = YES 则手势返回的时候就会触发。

出现这个现象的直接原因是 tabBar 内的按钮 UITabBarButton 被设置了错误的 frame,frame.size 变为 (0, 0) 导致的。

如果需要,可以使用以下临时修补代码,待发布的 QMUI 新版里也会带上这部分代码,等到 iOS 12.1 正式版发布后如果这个问题被修复,我们也会把这段代码移除。

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (@available(iOS 12.1, *)) {
            OverrideImplementation(NSClassFromString(@"UITabBarButton"), @selector(setFrame:), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP originIMP) {
                return ^(UIView *selfObject, CGRect firstArgv) {
                    
                    if ([selfObject isKindOfClass:originClass]) {
                        // 如果发现即将要设置一个 size 为空的 frame,则屏蔽掉本次设置
                        if (!CGRectIsEmpty(selfObject.frame) && CGRectIsEmpty(firstArgv)) {
                            return;
                        }
                    }
                    
                    // call super
                    void (*originSelectorIMP)(id, SEL, CGRect);
                    originSelectorIMP = (void (*)(id, SEL, CGRect))originIMP;
                    originSelectorIMP(selfObject, originCMD, firstArgv);
                };
            });
        }
    });
}

那如果UITabBar不是磨砂的呢?好像这个问题仍然存在,修改isTranslucent不起作用

@fujianjin6471

This comment has been minimized.

Copy link

commented Nov 19, 2018

iOS 12.1.1 Beta 3仍未修复

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Nov 19, 2018

实测这个问题是 iOS 12.1 Beta 2 的问题,只要 UITabBar 是磨砂的,并且 push viewController 时 hidesBottomBarWhenPushed = YES 则手势返回的时候就会触发。
出现这个现象的直接原因是 tabBar 内的按钮 UITabBarButton 被设置了错误的 frame,frame.size 变为 (0, 0) 导致的。
如果需要,可以使用以下临时修补代码,待发布的 QMUI 新版里也会带上这部分代码,等到 iOS 12.1 正式版发布后如果这个问题被修复,我们也会把这段代码移除。

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (@available(iOS 12.1, *)) {
            OverrideImplementation(NSClassFromString(@"UITabBarButton"), @selector(setFrame:), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP originIMP) {
                return ^(UIView *selfObject, CGRect firstArgv) {
                    
                    if ([selfObject isKindOfClass:originClass]) {
                        // 如果发现即将要设置一个 size 为空的 frame,则屏蔽掉本次设置
                        if (!CGRectIsEmpty(selfObject.frame) && CGRectIsEmpty(firstArgv)) {
                            return;
                        }
                    }
                    
                    // call super
                    void (*originSelectorIMP)(id, SEL, CGRect);
                    originSelectorIMP = (void (*)(id, SEL, CGRect))originIMP;
                    originSelectorIMP(selfObject, originCMD, firstArgv);
                };
            });
        }
    });
}

那如果UITabBar不是磨砂的呢?好像这个问题仍然存在,修改isTranslucent不起作用

@fujianjin6471 实测用 backgroundImage 的 tabBar 并不存在这个问题。

@codingiran

This comment has been minimized.

Copy link

commented Dec 6, 2018

12.1.1正式版已经修复此问题

@MoLice

This comment has been minimized.

Copy link
Collaborator

commented Dec 21, 2018

2.9.3 版本里已加上 < 12.1.1 的判断。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.