TabBarItem切换动画

为工程的底部工具栏添加一个简单而小萌的动画,原理是在 UITabBarController的里面切换Item时的方法中添加一个缩放动画。

实现的效果如下GIF图,




代码如下,

//tabbar选中item

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

{

    [selfanimationWithIndex:[self.tabBar.itemsindexOfObject:item]];

}


#pragma mark - TabBar Item选中时的动画

- (void)animationWithIndex:(NSInteger) index {

    

    NSMutableArray * tabBarButtonArray = [NSMutableArrayarray];

    for (UIView *tabBarButtonin self.tabBar.subviews) {

        if ([tabBarButtonisKindOfClass:NSClassFromString(@"UITabBarButton")]) {

            [tabBarButtonArray addObject:tabBarButton];

        }

    }

    CABasicAnimation * animation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    animation.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    animation.duration =0.1;

    animation.repeatCount =1;

    animation.autoreverses =YES;

    animation.fromValue =@0.6;

    animation.toValue =@1.4;

    [[tabBarButtonArray[index] layer]addAnimation:animation forKey:nil];

}



你可能感兴趣的:(TabBarItem切换动画)