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

版本v1.29.0 修复分割线和Lottie动画播放异常等bugs #494

Open
ChenYilong opened this issue May 5, 2020 · 6 comments
Open

版本v1.29.0 修复分割线和Lottie动画播放异常等bugs #494

ChenYilong opened this issue May 5, 2020 · 6 comments
Assignees
Labels

Comments

@ChenYilong
Copy link
Owner



今天把 CYLTabBarController 更新到1.29.0, 修了几个issue, 主要是顶部导航栏,
主要修复的功能:

  • TabBar 自定义分割线
  • 隐藏 TabBar 分割线的方法

将更新的代码贴一下:

TabBar 自定义分割线

// NO.1,using Image note:recommended.推荐方式
   // set the bar shadow image
   // without shadow : use -[[CYLTabBarController hideTabBarShadowImageView] in CYLMainRootViewController.m
   if (@available(iOS 13.0, *)) {
       UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance  alloc] init];
       // set the text Attributes
       // 设置文字属性
       [inlineLayoutAppearance.normal setTitleTextAttributes:normalAttrs];
       [inlineLayoutAppearance.selected setTitleTextAttributes:selectedAttrs];
   
       UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
       standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance;
       standardAppearance.backgroundColor = [UIColor cyl_systemBackgroundColor];
       standardAppearance.shadowImage = [[self class] imageWithColor:[UIColor cyl_systemGreenColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)];
       self.tabBar.standardAppearance = standardAppearance;
   } else {
       // Override point for customization after application launch.
       // set the text Attributes
       // 设置文字属性
       UITabBarItem *tabBar = [UITabBarItem appearance];
       [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
       [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
       
//        // This shadow image attribute is ignored if the tab bar does not also have a custom background image.So at least set somthing.
       [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
       [[UITabBar appearance] setShadowImage:[[self class] imageWithColor:[UIColor cyl_systemGreenColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)]];
   }

可以使用:

v1.29.0 更新了内部实现, 兼容了 iOS13+ ,和 iOS13- 版本.

-[[CYLTabBarController hideTabBarShadowImageView] 

其中重要的部分在于找到分割线对应的 View, 实现方法如下:

- (UIImageView *)cyl_tabShadowImageView {
   if (@available(iOS 10.0, *)) {
       //iOS10及以上这样获取ShadowImageView:
       UIView *subview = [self cyl_tabBackgroundView];
       if (!subview) {
           return nil;
       }
       NSArray<__kindof UIView *> *backgroundSubviews = subview.subviews;
       //iOS13系统backgroundSubviews.count > 1可行,12及以下就不可行了
       if (backgroundSubviews.count >= 1) {
           for (UIView *subview in backgroundSubviews) {
               if (CGRectGetHeight(subview.bounds) <= 1.0 ) {
                   return (UIImageView *)subview;
               }
           }
       }
   } else {
       //iOS9这样获取ShadowImageView:
       for (UIView *subview in self.subviews) {
           if (CGRectGetHeight(subview.bounds) <= 1.0 ) {
               return (UIImageView *)subview;
           }
       }
   }
   return nil;
}

隐藏 TabBar 分割线的方法

Lottie 动画在某些场景不播放的问题

详情参见 #423 issue.

fix issues:
#431
#436
#492
#423

项目地址: https://github.com/ChenYilong/CYLTabBarController

@ChenYilong ChenYilong added the Q-A label May 5, 2020
@ChenYilong ChenYilong self-assigned this May 5, 2020
@ChenYilong
Copy link
Owner Author

注意

UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
//shadowColor和shadowImage均可以自定义颜色, shadowColor默认高度为1, shadowImage可以自定义高度.
standardAppearance.shadowColor = [UIColor cyl_systemGreenColor];
// standardAppearance.shadowImage = [[self class] imageWithColor:[UIColor cyl_systemGreenColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)];

@Lee0820
Copy link

Lee0820 commented May 19, 2020

你好,我这么设置了确实达到了设置分割线的效果,但是 CYLTabBarItemTitlePositionAdjustment设置的偏移量就失效了,是时机问题不对吗?请问下作者,这个问题修复了吗?

@ChenYilong
Copy link
Owner Author

@Lee0820 偏移量相关的代码我没动,是不是不设置分割线就生效了?

@Lee0820
Copy link

Lee0820 commented May 19, 2020

对的,用UITabBarAppearance 设置 ShadowImage,后 CYLTabBarItemTitlePositionAdjustment设置的偏移量就失效了,我在微信也请教过这个问题,不知道是不是系统的bug,13.4.1,我用老api设置分割线也是有效的 [[UITabBar appearance] setShadowImage:,13.3上不行~

@ChenYilong
Copy link
Owner Author

@Lee0820 Lee 在这里回复你了 #456

@humoroutlaw
Copy link

humoroutlaw commented Oct 28, 2020

iOS 13.2.3 顶部横线无法显示,图层也看不到shadowImage.

- (void)customizeTabBarAppearance {
     [self rootWindow].backgroundColor = [UIColor cyl_systemBackgroundColor];


   NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
   normalAttrs[NSForegroundColorAttributeName] = [UIColor cyl_systemGrayColor];
   
   NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
   selectedAttrs[NSForegroundColorAttributeName] = [UIColor cyl_labelColor];
  
  if (@available(iOS 13.0, *)) {
          UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance  alloc] init];
          [inlineLayoutAppearance.normal setTitleTextAttributes:normalAttrs];
          [inlineLayoutAppearance.selected setTitleTextAttributes:selectedAttrs];
      
          UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
          standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance;
          standardAppearance.backgroundColor = [UIColor cyl_systemBackgroundColor];
          standardAppearance.shadowImage = [[self class] imageWithColor:[UIColor cyl_systemGreenColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)];
          self.tabBar.standardAppearance = standardAppearance;
      } else {
          UITabBarItem *tabBar = [UITabBarItem appearance];
          [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
          [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
          [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
          [[UITabBar appearance] setShadowImage:[[self class] imageWithColor:[UIColor cyl_systemGreenColor] size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)]];
      }
}

Uploading 191603897759_.pic.jpg…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants