tabbarItem动画

//写在TabBarController .m文件中
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSInteger index = [self.tabBar.items indexOfObject:item];
if (self.indexFlag != index) {
[self animationWithIndex:index];
    }
}

// 执行动画
- (void)animationWithIndex:(NSInteger)index {
NSMutableArray * tabbarbuttonArray = [NSMutableArray array]; 
for (UIView *tabBarButton in self.tabBar.subviews){
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[tabbarbuttonArray addObject:tabBarButton]; }
}
CABasicAnimation*action = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
action.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
action.duration = 0.08;
action.repeatCount= 1;
action.autoreverses= YES;
action.fromValue= [NSNumber numberWithFloat:0.7]; 
action.toValue= [NSNumber numberWithFloat:1.2]; 
[[tabbarbuttonArray[index] layer]
addAnimation:action forKey:nil]; 
self.indexFlag = index;
}


你可能感兴趣的:(tabbarItem动画)