tabBarItem动画

 1.有时,我们需要为tabBarItem设置一些动画。在网上查了半天,没有结果。自己写了一个简单的动画

代码如下:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    NSInteger currentIndex = tabBarController.selectedIndex;
    NSInteger index = 0;
    UITabBar *tabBar = tabBarController.tabBar;
    
    for (int i = 0; i < tabBar.subviews.count; i++) {
        
        UIView *button = tabBar.subviews[i];
        if ([button isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            if (index != currentIndex) {
                index++;
            }
            else{
                
                CAKeyframeAnimation *animation = [[CAKeyframeAnimation alloc]init];
                
                animation.keyPath = @"transform.scale";
                animation.duration = 1.0;
                animation.values = @[@(1.0) ,@(1.4), @(0.9), @(1.15), @(0.95), @(1.02), @(1.0)];
                
                
                UIView *imageview = [button.subviews firstObject];
                //view.backgroundColor = [UIColor greenColor];
                [imageview.layer addAnimation: animation forKey:nil];
                
                UIView *labelview = [button.subviews lastObject];
                [labelview.layer addAnimation:animation forKey:nil];
                break;

            }
            
            
        }
        
        
        
    }

}
原文地址:https://www.cnblogs.com/yintingting/p/4567155.html