demo

iOS电商项目之tabBar

2017-06-13  本文已影响64人  葱花饼

本项目tabBar点击后是可以变化大小的,具体看效果

tabBar

设置UITabBarController的代理

    self.delegate = self;

实现代理方法

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    NSInteger selectIndex = [tabBar.items indexOfObject:item];
    if (selectIndex != oldIndex) {
        [self animationWithIndex:selectIndex];
    }
}
- (void)animationWithIndex:(NSInteger)index
{
    // Image + Label动画
    NSMutableArray *animationArrayM = [NSMutableArray array];
    for (UIView *tabBarButton in self.tabBar.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [animationArrayM addObject:tabBarButton];
        }
    }
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"transform.scale";
    animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.02,@1.0];
    animation.duration = 1;
    animation.calculationMode = kCAAnimationCubic;
    
    // 添加动画
    [[animationArrayM[index] layer] addAnimation:animation forKey:nil];
    
}

这样就可以了

想要系统,具体的学习,请加群-------群号:647657839

上一篇下一篇

猜你喜欢

热点阅读