《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRTabbarController.m 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // DRTabbarController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRTabbarController.h"
  9. #import "DRCommunityLeftController.h"
  10. #import "DRNavigationController.h"
  11. #import "DRHomeMainViewController.h"
  12. #import "DRBrandMainViewController.h"
  13. #import "DRFindMainViewController.h"
  14. #import "DRMineMainViewController.h"
  15. #import "DRCollectionViewController.h"
  16. #import "DRCollectionMainViewController.h"
  17. #import "DRClassifyViewController.h"
  18. #import "DRCommunityViewController.h"
  19. #import "KBUniteShopCarViewController.h"
  20. #import "DRTimeLineViewController.h"
  21. @interface DRTabbarController ()<UITabBarControllerDelegate>
  22. @property (nonatomic,assign) NSInteger indexFlag;
  23. @end
  24. @implementation DRTabbarController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self setUpAllChildVc];
  28. }
  29. - (void)setUpAllChildVc
  30. {
  31. [self setUpOneChildVcWithVc:[[DRHomeMainViewController alloc] init] Image:@"tab_home_n" selectedImage:@"tab_home_s" title:@"首页"];
  32. // [self setUpOneChildVcWithVc:[[LDNineNineMainViewController alloc] init] Image:@"tab_99" selectedImage:@"tab_99_selected" title:@"9块9"];
  33. // [self setUpOneChildVcWithVc:[[DRBrandMainViewController alloc] init] Image:@"tab_brand" selectedImage:@"tab_brand_selected" title:@"品牌优选"];
  34. [self setUpOneChildVcWithVc:[[DRTimeLineViewController alloc] init] Image:@"tab_good_n" selectedImage:@"tab_good_s" title:@"优选"];
  35. [self setUpOneChildVcWithVc:[[KBUniteShopCarViewController alloc] init] Image:@"tab_car_n" selectedImage:@"tab_car_s" title:@"购物车"];
  36. [self setUpOneChildVcWithVc:[[DRMineMainViewController alloc] init] Image:@"tab_mine_n" selectedImage:@"tab_mine_s" title:@"我的"];
  37. }
  38. - (void)setUpOneChildVcWithVc:(UIViewController *)Vc Image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title
  39. {
  40. [Vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor baseColor]} forState:UIControlStateSelected];
  41. DRNavigationController *nav = [[DRNavigationController alloc] initWithRootViewController:Vc];
  42. UIImage *myImage = [UIImage imageNamed:image];
  43. myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  44. Vc.tabBarItem.image = myImage;
  45. UIImage *mySelectedImage = [UIImage imageNamed:selectedImage];
  46. mySelectedImage = [mySelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  47. Vc.tabBarItem.selectedImage = mySelectedImage;
  48. Vc.tabBarItem.title = title;
  49. Vc.navigationItem.title = title;
  50. [self addChildViewController:nav];
  51. }
  52. - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
  53. NSInteger index = [self.tabBar.items indexOfObject:item];
  54. if (index != self.indexFlag) {
  55. //执行动画
  56. NSMutableArray *arry = [NSMutableArray array];
  57. for (UIView *btn in self.tabBar.subviews) {
  58. if ([btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
  59. [arry addObject:btn];
  60. }
  61. }
  62. //添加动画
  63. //---将下面的代码块直接拷贝到此即可---
  64. self.indexFlag = index;
  65. [self clickAnimationWithIndex:index arr:arry];
  66. }
  67. }
  68. - (void)clickAnimationWithIndex:(NSInteger)index arr:(NSArray *)arry{
  69. //放大效果,并回到原位
  70. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  71. //速度控制函数,控制动画运行的节奏
  72. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  73. animation.duration = 0.2; //执行时间
  74. animation.repeatCount = 1; //执行次数
  75. animation.autoreverses = YES; //完成动画后会回到执行动画之前的状态
  76. animation.fromValue = [NSNumber numberWithFloat:0.7]; //初始伸缩倍数
  77. animation.toValue = [NSNumber numberWithFloat:1.1]; //结束伸缩倍数
  78. [[arry[index] layer] addAnimation:animation forKey:nil];
  79. }
  80. - (void)didReceiveMemoryWarning {
  81. [super didReceiveMemoryWarning];
  82. // Dispose of any resources that can be recreated.
  83. }
  84. /*
  85. #pragma mark - Navigation
  86. // In a storyboard-based application, you will often want to do a little preparation before navigation
  87. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  88. // Get the new view controller using [segue destinationViewController].
  89. // Pass the selected object to the new view controller.
  90. }
  91. */
  92. @end