123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // DRTabbarController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRTabbarController.h"
- #import "DRNavigationController.h"
- #import "DRHomeMainViewController.h"
- #import "DRNineNineMainViewController.h"
- #import "DRBrandMainViewController.h"
- #import "DRFindMainViewController.h"
- #import "DRMineMainViewController.h"
- #import "DRCollectionViewController.h"
- #import "DRCollectionMainViewController.h"
- #import "DRClassifyViewController.h"
- #import "DRCommunityViewController.h"
- #import "DRCommunityLeftController.h"
- @interface DRTabbarController ()<UITabBarControllerDelegate>
- @property (nonatomic,assign) NSInteger indexFlag;
- @end
- @implementation DRTabbarController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self setUpAllChildVc];
- }
- - (void)setUpAllChildVc
- {
- [self setUpOneChildVcWithVc:[[DRHomeMainViewController alloc] init] Image:@"tab_home" selectedImage:@"tab_home_selected" title:@"首页"];
- // [self setUpOneChildVcWithVc:[[DRNineNineMainViewController alloc] init] Image:@"tab_99" selectedImage:@"tab_99_selected" title:@"9块9"];
- // [self setUpOneChildVcWithVc:[[DRBrandMainViewController alloc] init] Image:@"tab_brand" selectedImage:@"tab_brand_selected" title:@"品牌优选"];
- [self setUpOneChildVcWithVc:[[DRClassifyViewController alloc] init] Image:@"tab_classify_n" selectedImage:@"tab_classify_s" title:@"分类"];
- [self setUpOneChildVcWithVc:[[DRCommunityLeftController alloc] init] Image:@"tab_zhuanqian_n" selectedImage:@"tab_zhuanqian_s" title:@"优选"];
- [self setUpOneChildVcWithVc:[[DRMineMainViewController alloc] init] Image:@"tab_mine" selectedImage:@"tab_mine_selected" title:@"我的"];
-
- }
- - (void)setUpOneChildVcWithVc:(UIViewController *)Vc Image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title
- {
- [Vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor baseColor]} forState:UIControlStateSelected];
- DRNavigationController *nav = [[DRNavigationController alloc] initWithRootViewController:Vc];
-
- UIImage *myImage = [UIImage imageNamed:image];
- myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- Vc.tabBarItem.image = myImage;
-
- UIImage *mySelectedImage = [UIImage imageNamed:selectedImage];
- mySelectedImage = [mySelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- Vc.tabBarItem.selectedImage = mySelectedImage;
-
- Vc.tabBarItem.title = title;
-
- Vc.navigationItem.title = title;
-
- [self addChildViewController:nav];
- }
- - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
- NSInteger index = [self.tabBar.items indexOfObject:item];
- if (index != self.indexFlag) {
- //执行动画
- NSMutableArray *arry = [NSMutableArray array];
- for (UIView *btn in self.tabBar.subviews) {
- if ([btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
- [arry addObject:btn];
- }
- }
- //添加动画
- //---将下面的代码块直接拷贝到此即可---
- self.indexFlag = index;
- [self clickAnimationWithIndex:index arr:arry];
-
- }
- }
- - (void)clickAnimationWithIndex:(NSInteger)index arr:(NSArray *)arry{
- //放大效果,并回到原位
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- //速度控制函数,控制动画运行的节奏
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- animation.duration = 0.2; //执行时间
- animation.repeatCount = 1; //执行次数
- animation.autoreverses = YES; //完成动画后会回到执行动画之前的状态
- animation.fromValue = [NSNumber numberWithFloat:0.7]; //初始伸缩倍数
- animation.toValue = [NSNumber numberWithFloat:1.1]; //结束伸缩倍数
- [[arry[index] layer] addAnimation:animation forKey:nil];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|