TabBar修改颜色,动画

你离开我真会死。 提交于 2020-08-16 04:23:57
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    if ([tabBar.selectedItem.title isEqualToString:NTVLocalized(@"TabBar1", nil)]) {
        tabBar.tintColor = [UIColor rgb:@"2ED1EF"];

    }else if ([tabBar.selectedItem.title isEqualToString:NTVLocalized(@"contacts", nil)]){
        tabBar.tintColor =  [UIColor rgb:@"FF4888"];
        
        ZGBaseNavigationController *nav = (ZGBaseNavigationController *)[self.viewControllers objectAtIndex:1];
        WFCUContactListViewController *contact = (WFCUContactListViewController *) nav.viewControllers.firstObject;
        [contact loadContact];

    }else if ([tabBar.selectedItem.title isEqualToString:NTVLocalized(@"discovery", nil)]){
        tabBar.tintColor = [UIColor rgb:@"DB4FF9"];

    }else if ([tabBar.selectedItem.title isEqualToString:NTVLocalized(@"mine", nil)]){
        tabBar.tintColor = [UIColor rgb:@"FFAD00"];

    }else if ([tabBar.selectedItem.title isEqualToString:NTVLocalized(@"live", nil)]){
        tabBar.tintColor = [UIColor rgb:@"FF4888"];

    }

    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];
    }
}
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!