1.在建立tabBarItem時先給每個tabBarItem一個tag值。app
2.在tabBarItem的點擊方法中添加阻尼動畫效果。動畫
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {spa
NSInteger index = 1;orm
NSInteger clickTag = item.tag - 1000;ci
for (UIView *subview in tabBar.subviews) {animation
if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {it
if(index == clickTag){io
for (UIView *v in subview.subviews) {form
if ([v isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {cli
[UIView animateWithDuration:0.15 delay:0 usingSpringWithDamping:1 initialSpringVelocity:9.8 options:0 animations:^{
v.transform = CGAffineTransformMakeScale(0.7, 0.7);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.15 animations:^{
v.transform = CGAffineTransformMakeScale(1.3, 1.3);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.15 animations:^{
v.transform = CGAffineTransformIdentity;
}];
}];
}];
}
}
}
index++;
}
}
}