在UITabBarController代理方法中添加动画,先通过KVC获取UIControl,然后在获取上面的UITabBarSwappableImageView,最后将动画添加到imageview的layer上。
#pragma mark UITabBarControllerDelegate的代理方法 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { UIControl*tabBarButton = [viewController.tabBarItem valueForKey:@"view"]; if (tabBarButton) { UIImageView * tabBarSwappableImageView = [tabBarButton valueForKey:@"info"]; if ([tabBarSwappableImageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) { CAKeyframeAnimation * animation; animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; animation.duration = 0.3; animation.removedOnCompletion = YES; animation.fillMode = kCAFillModeForwards; NSMutableArray *values = [NSMutableArray array]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]]; animation.values = values; [tabBarSwappableImageView.layer addAnimation:animation forKey:nil]; } } return YES; }