美文网首页
iOS12系统之后页面切换TabBar错乱问题处理

iOS12系统之后页面切换TabBar错乱问题处理

作者: 吃大米的小蚂蚁 | 来源:发表于2023-05-04 18:45 被阅读0次

    主要就是OS 12.1 Beta 2 引入的问题,只要 UITabBar 是磨砂的,并且 push viewController 时 hidesBottomBarWhenPushed = YES 则手势返回的时候就会触发。解决方法如下,在项目中添加一个UIView分类,在.m文件里设置好你的tabbar正确的尺寸,即可正常运行。
    伸手党的快乐,拿走
    .h文件

    import <UIKit/UIKit.h>

    NS_ASSUME_NONNULL_BEGIN

    @interface UIView (LLTabBarItem)

    @end

    NS_ASSUME_NONNULL_END

    .m文件

    import "UIView+LLTabBarItem.h"

    import <objc/runtime.h>

    @implementation UIView (CKTabBarItem)

    • (void)load
      {
      if (@available(iOS 12.1, *)) {
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
      Class class = NSClassFromString(@"UITabBarButton");
      SEL originalSelector = @selector(setFrame:);
      SEL swizzledSelector = @selector(ck_setFrame:);
      Method originalMethod = class_getInstanceMethod(class, originalSelector);
      Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
      BOOL isSuccess = class_addMethod(class,
      originalSelector,
      method_getImplementation(swizzledMethod),
      method_getTypeEncoding(swizzledMethod));
      if (isSuccess) {
      class_replaceMethod(class,
      swizzledSelector,
      method_getImplementation(originalMethod),
      method_getTypeEncoding(originalMethod));
      } else {
      method_exchangeImplementations(originalMethod, swizzledMethod);
      }
      });
      }
      }
    • (void)ck_setFrame:(CGRect)frame
      {
      if (!CGRectIsEmpty(self.frame)) {
      if (CGRectIsEmpty(frame)) {
      return;
      }
      frame.size.height = MAX(frame.size.height, 60.0);
      }
      [self ck_setFrame: frame];
      }

    @end

    相关文章

      网友评论

          本文标题:iOS12系统之后页面切换TabBar错乱问题处理

          本文链接:https://www.haomeiwen.com/subject/jooxsdtx.html