在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; }
本文详细介绍了如何在iOS应用中为UITabBarController的选中状态添加动画效果。通过使用KVC获取UIControl及UITabBarSwappableImageView,作者展示了如何自定义动画并将其应用于tabBar的图标上,实现图标缩放的视觉效果。

1764

被折叠的 条评论
为什么被折叠?



