- (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];
}
}
}
来源:oschina
链接:https://my.oschina.net/wayzhu/blog/4299188