UITabBar items jumping on back navigation on iOS 12.1

后端 未结 12 978
北恋
北恋 2020-11-29 18:28

I have an iOS app with UITabBarController on a master screen, navigating to a detail screen hiding the UITabBarController with setting hidesB

12条回答
  •  醉梦人生
    2020-11-29 19:01

    there are two ways to fix this issue, Firstly, In your UITabBarController, set isTranslucent = false like:

    [[UITabBar appearance] setTranslucent:NO];
    

    sencondly, if the first solution does not fix your issur, try this way:

    here is the Objective-C code

    // .h
    @interface CYLTabBar : UITabBar
    @end 
    
    // .m
    #import "CYLTabBar.h"
    
    CG_INLINE BOOL
    OverrideImplementation(Class targetClass, SEL targetSelector, id (^implementationBlock)(Class originClass, SEL originCMD, IMP originIMP)) {
       Method originMethod = class_getInstanceMethod(targetClass, targetSelector);
       if (!originMethod) {
           return NO;
       }
       IMP originIMP = method_getImplementation(originMethod);
       method_setImplementation(originMethod, imp_implementationWithBlock(implementationBlock(targetClass, targetSelector, originIMP)));
       return YES;
    }
    @implementation CYLTabBar
    
    + (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]) {
    
                           if (!CGRectIsEmpty(selfObject.frame) && CGRectIsEmpty(firstArgv)) {
                               return;
                           }
                       }
    
                       // call super
                       void (*originSelectorIMP)(id, SEL, CGRect);
                       originSelectorIMP = (void (*)(id, SEL, CGRect))originIMP;
                       originSelectorIMP(selfObject, originCMD, firstArgv);
                   };
               });
           }
       });
    }
    @end
    

    More information:https://github.com/ChenYilong/CYLTabBarController/commit/2c741c8bffd47763ad2fca198202946a2a63c4fc

提交回复
热议问题