//
// AppDelegate.m
#import "AppDelegate.h"
#import "MyTabBarViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
// 把tabbarview作为根视图 //
MyTabBarViewController*tab=[[MyTabBarViewControlleralloc]init];
self.window.rootViewController=tab;
//////******************//////
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
return YES;
}
@end
// MyTabBarViewController.h
// HHXX
//
// Created by CG on 15/4/7.
// Copyright (c) 2015年 CG. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MyTabBarViewController :UITabBarController
@property(nonatomic)UIButton*tabbar_Button1;
@property(nonatomic)UIButton*tabbar_Button2;
@property(nonatomic)UIButton*tabbar_Button3;
@property(nonatomic)UIButton*tabbar_Button4;
@property(nonatomic)UIImageView*tabbar_ImageView;
@property(nonatomic)UIImage*tabbar_Image;
@property(nonatomic)UIButton*custom_Button;
@property(nonatomic)NSArray*picture_Array;
@property(nonatomic)NSArray*picturSelect_Array;
@end
//
// MyTabBarViewController.m
// HHXX
//
// Created by CG on 15/4/7.
// Copyright (c) 2015年 CG. All rights reserved.
//
#import "MyTabBarViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
#import "FourViewController.h"
@interface MyTabBarViewController ()
@end
@implementation MyTabBarViewController
第一次加载
static bool FIRST=YES;
static bool first=YES;
/// 隐藏tabbar,判断,不是很懂 /
-(void)hideRealTabBar{
for(UIView *viewinself.view.subviews){
if([viewisKindOfClass:[UITabBarclass]]){
view.hidden =YES;
break;
}
}
}
/ 显示tabbar ///
-(void)showCustomTabBar
{
[selfperformSelector:@selector(hideRealTabBar)];
[_tabbar_ImageViewsetHidden:NO];
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];
animation.duration =0.25;
animation.delegate =self;
animation.removedOnCompletion =YES;
animation.fillMode =kCAFillModeForwards;
NSMutableArray *values = [NSMutableArrayarray];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.0,0.0,0.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.5,0.5,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.5,1.0,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0,1.0)]];
animation.values = values;
[_tabbar_ImageView.layeraddAnimation:animationforKey:nil];
}
// /隐藏tabbar /
-(void)hideCustomTabBar
{
[selfperformSelector:@selector(hideRealTabBar)];
CAKeyframeAnimation*animation;
animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];
animation.duration =0.01;
animation.delegate =self;
animation.removedOnCompletion =YES;
animation.fillMode =kCAFillModeForwards;
NSMutableArray *values = [NSMutableArrayarray];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.5,1.0,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.5,0.5,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.0,0.0,0.0)]];
animation.values = values;
[_tabbar_ImageView.layeraddAnimation:animationforKey:nil];
}
/// 自定义tabbar button图片 //
-(void)createCustomTabBar
{
//隐藏
self.tabBar.hidden=YES;
/// tabbarview ///
_tabbar_ImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(0,self.view.bounds.size.height-49,self.tabBar.bounds.size.width,49)];
_tabbar_ImageView.backgroundColor=[UIColoryellowColor];
_tabbar_ImageView.userInteractionEnabled=YES;
[self.viewaddSubview:_tabbar_ImageView];
/// 图片数组,准备button图片 //
_picture_Array=[[NSArrayalloc]init];
_picture_Array=[NSArrayarrayWithObjects:@"deng2",@"flag1",@"message1",@"star0",nil];
for (int i=3; i>=0; i--) {
_custom_Button=[UIButtonbuttonWithType:UIButtonTypeCustom];
_tabbar_Image=[UIImageimageNamed:[_picture_ArrayobjectAtIndex:i]];
[_custom_ButtonsetBackgroundImage:_tabbar_ImageforState:UIControlStateNormal];
/ button位置 //
if (i==3) {
_tabbar_Button4=_custom_Button;
_custom_Button.frame=CGRectMake(self.tabBar.bounds.size.width/4*3,0,self.tabBar.bounds.size.width/4,49);
[_tabbar_Button4addTarget:selfaction:@selector(tunto4)forControlEvents:UIControlEventTouchUpInside];
}
if (i==2) {
_tabbar_Button3=_custom_Button;
_custom_Button.frame=CGRectMake(self.tabBar.bounds.size.width/2,0,self.tabBar.bounds.size.width/4,49);
[_tabbar_Button3addTarget:selfaction:@selector(tunto3)forControlEvents:UIControlEventTouchUpInside];
}
if (i==1) {
_tabbar_Button2=_custom_Button;
_custom_Button.frame=CGRectMake(self.tabBar.bounds.size.width/4,0,self.tabBar.bounds.size.width/4,49);
[_tabbar_Button2addTarget:selfaction:@selector(tunto2)forControlEvents:UIControlEventTouchUpInside];
}
if (i==0) {
_tabbar_Button1=_custom_Button;
_custom_Button.frame=CGRectMake(0,0,self.tabBar.bounds.size.width/4,49);
[_tabbar_Button1addTarget:selfaction:@selector(tunto1)forControlEvents:UIControlEventTouchUpInside];
// 第一次加载,确保_tabbar_Button1的正确
_tabbar_Button1.adjustsImageWhenHighlighted = NO; //没有会很煞笔
if (first) {
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:@"deng1"]forState:UIControlStateNormal];
first=NO;
}
}
_custom_Button.tag=i;
[_tabbar_ImageViewaddSubview:_custom_Button];
self.selectedIndex=_custom_Button.tag;
}
}
//////******************//
// 暂留 ///
/*
//点击变图片
-(void)_custom_ButtonClick:(UIButton*)button
{
_picturSelect_Array=[[NSArray alloc]init];
_picturSelect_Array=[NSArray arrayWithObjects:@"5",@"6",@"7",@"8", nil];
[_tabbar_Button1 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:0]] forState:UIControlStateHighlighted];
[_tabbar_Button2 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:1]] forState:UIControlStateHighlighted];
[_tabbar_Button3 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:2]] forState:UIControlStateHighlighted];
[_tabbar_Button4 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:3]] forState:UIControlStateHighlighted];
switch (_custom_Button.tag) {
case 0:
{
[_tabbar_Button1 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:0]] forState:UIControlStateNormal];
[_tabbar_Button2 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:1]] forState:UIControlStateNormal];
[_tabbar_Button3 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:2]] forState:UIControlStateNormal];
[_tabbar_Button4 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:3]] forState:UIControlStateNormal];
}
break;
case 1:
{
[_tabbar_Button1 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:0]] forState:UIControlStateNormal];
[_tabbar_Button2 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:1]] forState:UIControlStateNormal];
[_tabbar_Button3 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:2]] forState:UIControlStateNormal];
[_tabbar_Button4 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:3]] forState:UIControlStateNormal];
}
break;
case 2:
{
[_tabbar_Button1 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:0]] forState:UIControlStateNormal];
[_tabbar_Button2 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:1]] forState:UIControlStateNormal];
[_tabbar_Button3 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:2]] forState:UIControlStateNormal];
[_tabbar_Button4 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:3]] forState:UIControlStateNormal];
}
break;
case 3:
{
//[_tabbar_Button1 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:0]] forState:UIControlStateNormal];
//[_tabbar_Button2 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:1]] forState:UIControlStateNormal];
//[_tabbar_Button3 setBackgroundImage:[UIImage imageNamed:[_picture_Array objectAtIndex:2]] forState:UIControlStateNormal];
//[_tabbar_Button4 setBackgroundImage:[UIImage imageNamed:[_picturSelect_Array objectAtIndex:3]] forState:UIControlStateNormal];
}
break;
default:
break;
}
//选中那个那个亮
self.selectedIndex=_custom_Button.tag; //必须在这里
}
*/
/ 切换试图的图片转换
-(void)changeview:(NSInteger)num
{
_picturSelect_Array=[[NSArrayalloc]init];
_picturSelect_Array=[NSArrayarrayWithObjects:@"deng1",@"flag2",@"message2",@"star2",nil];
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:[_picturSelect_Array objectAtIndex:0]]forState:UIControlStateHighlighted];
[_tabbar_Button2setBackgroundImage:[UIImageimageNamed:[_picturSelect_Array objectAtIndex:1]]forState:UIControlStateHighlighted];
[_tabbar_Button3setBackgroundImage:[UIImageimageNamed:[_picturSelect_Array objectAtIndex:2]]forState:UIControlStateHighlighted];
[_tabbar_Button4setBackgroundImage:[UIImageimageNamed:[_picturSelect_Array objectAtIndex:3]]forState:UIControlStateHighlighted];
switch (num) {
case0:
{
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:[_picturSelect_ArrayobjectAtIndex:0]]forState:UIControlStateNormal];
[_tabbar_Button2setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:1]]forState:UIControlStateNormal];
[_tabbar_Button3setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:2]]forState:UIControlStateNormal];
[_tabbar_Button4setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:3]]forState:UIControlStateNormal];
}
break;
case1:
{
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:0]]forState:UIControlStateNormal];
[_tabbar_Button2setBackgroundImage:[UIImageimageNamed:[_picturSelect_ArrayobjectAtIndex:1]]forState:UIControlStateNormal];
[_tabbar_Button3setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:2]]forState:UIControlStateNormal];
[_tabbar_Button4setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:3]]forState:UIControlStateNormal];
}
break;
case2:
{
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:0]]forState:UIControlStateNormal];
[_tabbar_Button2setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:1]]forState:UIControlStateNormal];
[_tabbar_Button3setBackgroundImage:[UIImageimageNamed:[_picturSelect_ArrayobjectAtIndex:2]]forState:UIControlStateNormal];
[_tabbar_Button4setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:3]]forState:UIControlStateNormal];
}
break;
case3:
{
[_tabbar_Button1setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:0]]forState:UIControlStateNormal];
[_tabbar_Button2setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:1]]forState:UIControlStateNormal];
[_tabbar_Button3setBackgroundImage:[UIImageimageNamed:[_picture_ArrayobjectAtIndex:2]]forState:UIControlStateNormal];
[_tabbar_Button4setBackgroundImage:[UIImageimageNamed:[_picturSelect_ArrayobjectAtIndex:3]]forState:UIControlStateNormal];
}
break;
default:
break;
}
}
//////******************//
- (void)viewDidLoad {
[superviewDidLoad];
/// 通知切换视图 ///
if (FIRST) {
隐藏tabbar用,通知???///
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"hideCustomTabBar"object:nil];
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(hideCustomTabBar)
name:@"hideCustomTabBar"
object:nil];
显示tabbar用,通知???///
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"showCustomTabBar"object:nil];
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(showCustomTabBar)
name:@"showCustomTabBar"
object:nil];
/*暂留
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(tunto2)
name: @"usercenter"
object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(turnTo1stInformationForcroninfo:)
name: @"croninfo"
object: nil];
*/
[selfhideRealTabBar];
FIRST =NO;
}
//////******************//
加载导航栏
OneViewController*oneview=[[OneViewControlleralloc]init];
UINavigationController*onenav=[[UINavigationControlleralloc]initWithRootViewController:oneview];
TwoViewController*twoview=[[TwoViewControlleralloc]init];
UINavigationController*twonav=[[UINavigationControlleralloc]initWithRootViewController:twoview];
ThreeViewController*threeview=[[ThreeViewControlleralloc]init];
UINavigationController*threenav=[[UINavigationControlleralloc]initWithRootViewController:threeview];
FourViewController*fourview=[[FourViewControlleralloc]init];
UINavigationController*fournav=[[UINavigationControlleralloc]initWithRootViewController:fourview];
self.viewControllers=[NSArrayarrayWithObjects:onenav,twonav,threenav,fournav,nil];
[selfcreateCustomTabBar]; //加载自定义的 tabbar
}
//////******************//
// 切换方法 //
-(void)tunto1
{
self.selectedIndex=0;
[selfchangeview:0];
}
-(void)tunto2
{
self.selectedIndex=1;
[selfchangeview:1];
}
-(void)tunto3
{
self.selectedIndex=2;
[selfchangeview:2];
}
-(void)tunto4
{
self.selectedIndex=3;
[selfchangeview:3];
}
//////******************//
/// 动画结束回调,用于隐藏,显示tabar //
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if (anim.duration==0.01) {
[_tabbar_ImageViewsetHidden:YES];
}
}
//////******************//
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
}
*/
@end