實(shí)現(xiàn)思路:通過遍歷tabBar的subviews拿到到點(diǎn)擊的view,然后再做動畫效果
在UITabBarController繼承類上對didSelectItem操作
indexFlag:全局變量:作用是防止重復(fù)點(diǎn)擊相同的bar觸發(fā)動畫效果
下面的代碼的動畫消果是:點(diǎn)擊縮小再恢復(fù)原樣
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSInteger index = [self.tabBar.items indexOfObject:item];
if (self.indexFlag == index) {
return;
}
NSMutableArray *btnArray = [NSMutableArray array];
for (UIView *barView in self.tabBar.subviews) {
if ([barView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[btnArray addObject:barView];
}
}
UIView *btnView = [btnArray objectAtIndex:index];
for (UIImageView *btnImageView in btnView.subviews) {
if ([btnImageView isKindOfClass:[UIImageView class]]) {
[UIView animateWithDuration:0.15 animations:^{
btnImageView.transform = CGAffineTransformMakeScale(0.7, 0.7);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.15 animations:^{
btnImageView.transform = CGAffineTransformIdentity;
}];
}];
}
}
self.indexFlag = index;
}