Tabbar 学习记录

1、设置透明Tabbar

    self.tabBar.translucent = YES;

    if (@available(iOS 13, *)) {

        UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];

        appearance.backgroundImage = [UIImage imageWithColor:[UIColor clearColor]];

        appearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];

        [appearance configureWithTransparentBackground];

        self.tabBar.standardAppearance = appearance;

   } else {

       self.tabBar.backgroundImage = [UIImage new];

       self.tabBar.shadowImage = [UIImage new];

   }

---基础设置

//设置背景颜色
self.tabBar.translucent = NO;
self.tabBar.barTintColor = [UIColor qqz_colorWithRGBHex:0x475769];

[[UITabBar appearance] setTintColor:YYTColorStr(@"")];//选中字体颜色
[[UITabBar appearance] setUnselectedItemTintColor:YYTColorStr(@"")];//未选中字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:UIPingFangSCMediumFont(11)} forState:UIControlStateNormal];//设置字体大小

UITabBarController、TabBar背景颜色设置、TabBarItem颜色处理 - 简书在iOS的开发过程中我们使用最多的框架结构估计就是UITabBarController + UINavigationController架构了,然而在开发过程中,对于许多初学...https://www.jianshu.com/p/962c14794f5b

2、中间按钮放大效果

简单实现UITabBarController,TabBar自定义,使中间按钮放大_zhanglizhi111的博客-CSDN博客本文通过继承UITabBarController,简单实现中间按钮放大功能样式:#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface MainTabBarViewController : UITabBarController+ (instancetype)instance;@end#impo...https://blog.csdn.net/zhanglizhi111/article/details/102662924

3、只放图片,并将图片位置向下调整

-(void)viewWillLayoutSubviews{
    for (int i = 0; i<self.tabBar.items.count; i ++) {
        UITabBarItem *itm = self.tabBar.items[i];
        itm.imageInsets = UIEdgeInsetsMake(10, 0, -10, 0);
    }
}

4、tabbar点击动效

点击后文字放大

 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
 {
 //重新设置所有 item 的字体
     for (UITabBarItem *unSelItem in tabBar.items) {
         if (unSelItem == item) {//选中的设置他的状态
             NSDictionary *textTitleOptions = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12]};
             [item setTitleTextAttributes:textTitleOptions forState:UIControlStateNormal];
         }else {//未选中的设置他的状态
             NSDictionary *textTitleOptions = @{NSFontAttributeName:[UIFont systemFontOfSize:10]};
             [unSelItem setTitleTextAttributes:textTitleOptions forState:UIControlStateNormal];
         }
     }
 }

点击后放大缩小等效果

给tabBarItem加点击效果动画 - 简书首先获取到tabBarItem,然后添加喜欢的动画,直接附代码https://www.jianshu.com/p/cc900e7b4ae2[先放大再缩小、Z轴旋转、向上移动、放大并保持]

tab点击,图片放大缩小动画_super_niuxinhuai的博客-CSDN博客项目中这次改版应产品要求加入tabbar点击做放大缩小动画,只改变图片,标题不做动画。先看效果图Demo地址图片做放大缩小动画,很好做。用CoreAnimation的帧动画就可以实现。不过貌似系统并没有开出开关于tabbar上的imageView这个属性。其实我们找到在tab上的imageView,这一切问题就好解决了。直接上代码声明一个tab继承系统tabbar#import https://blog.csdn.net/super_niuxinhuai/article/details/78761708UITabbarItem imageview 实现点击有放大然后还原的动画效果 - &清风& - 博客园在UITabBarController代理方法中添加动画,先通过KVC获取UIControl,然后在获取上面的UITabBarSwappableImageView,最后将动画添加到imageview的https://www.cnblogs.com/weipeng168/p/10270409.html点击后图片弹动效果

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        for (UIControl *tabBarButton in self.tabBar.subviews) {
            if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
                [tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            }
        }
    });
    
}

- (void)tabBarButtonClick:(UIControl *)tabBarButton
{
    for (UIView *imageView in tabBarButton.subviews) {
        if ([imageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
            //需要实现的帧动画,这里根据需求自定义
            CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
            animation.keyPath = @"transform.scale";
            animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.05,@1.0];
            animation.duration = 1;
            animation.calculationMode = kCAAnimationCubic;
            //把动画添加上去就OK了
            [imageView.layer addAnimation:animation forKey:nil];
        }
    }
}

点击后产生动图效果

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    
    NSInteger beforeIndex = self.beforeSelected;
    NSInteger currentIndex = [self getSelectedIndexWithTitle:item.title];
    
    
    // 如果选中的是当前选中的,不做动画
    if (beforeIndex == currentIndex) {
        return;
    }
    
    // 选中交易不做动画
    if (currentIndex == 2) {
        return;
    }
    
    UIImageView *originImageView = item.qmui_imageView;
    CGRect frame = originImageView.frame;
    item.qmui_imageView.hidden = YES;
    
    //所有的item,如果还在动画期间删除之前的动画,除了当前选中的item的,别的item的图片不隐藏
    for (UITabBarItem *i in self.tabBar.items) {
        if (![i.title isEqualToString:item.title]) {
            i.qmui_imageView.hidden = NO;
        }
        for (id obj in i.qmui_barButton.subviews) {
            if ([obj isKindOfClass:[LOTAnimationView class]]) {
                LOTAnimationView *v = obj;
                [v removeFromSuperview];
                v.hidden = YES;
            }
        }
    }
    
    NSString *animationName = item.title;
    if (![UUTokenLocalizable isChina]) {
        if ([item.title isEqualToString:@"Wallet"]) {
            animationName = @"钱包";
        }else if ([item.title isEqualToString:@"Market"]) {
            animationName = @"市场";
        }else if ([item.title isEqualToString:@"Mine"]) {
            animationName = @"我的";
        }
    }
    
    if ([item.title isEqualToString:WCJ_LocalString(@"UUTOKEN_TRANSACTION")]) {
        animationName = @"交易-暗黑";
    }
    LOTAnimationView *animationView = [LOTAnimationView animationNamed:animationName];
    animationView.backgroundColor = [UIColor clearColor];
    animationView.contentMode = UIViewContentModeScaleAspectFit;
    animationView.frame = frame;
    [item.qmui_barButton addSubview:animationView];
    animationView.loopAnimation = NO;
    animationView.animationProgress = 0;
    [animationView play];
    
    @weakify(animationView);
    [animationView setCompletionBlock:^(BOOL animationFinished) {
        @strongify(animationView);
        animationView.hidden = YES;
        [animationView removeFromSuperview];
        item.qmui_imageView.hidden = NO;
    }];
    
    self.beforeSelected = currentIndex;
}
【参考uu】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值