设置UITabBar自己为代理实现页面的动画转场(MS)

来源:互联网 发布:node 绑定域名 编辑:程序博客网 时间:2024/06/05 20:29

#import "ViewController.h"


@interfaceViewController ()

{

   UIView * _view0;

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // 设置屏幕背景色

    self.view.backgroundColor = [UIColorwhiteColor];

    // 加载view

    [self_loadViews];

    

    

    // 加载tabbar

    [self_loadTabBar];

   

    

}


- (void)_loadTabBar{

    

    

   

    

    // 初始化UITabBar

    UITabBar * tabBar = [[UITabBaralloc]initWithFrame:CGRectMake(0,self.view.frame.size.height -49, self.view.frame.size.width,49)];

    tabBar.delegate =self;// 设置自己为代理

    

    // 初始化barItem

   UIImage * imgForItem1 = [UIImageimageNamed:@"icon_cinema"];

    UIImage * imgForItem2 = [[UIImageimageNamed:@"icon_cinema@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

   UITabBarItem * item1 = [[UITabBarItemalloc]initWithTitle:@"Cinema"image:imgForItem1 selectedImage:imgForItem2];

    item1.tag =100;

    

    UITabBarItem * item2 = [[UITabBarItemalloc]initWithTitle:@"2"image:[UIImageimageNamed:@"more_select_setting"]tag:101];

    

    UITabBarItem * item3 = [[UITabBarItemalloc]initWithTitle:@"3"image:[UIImageimageNamed:@"movie_cinema"]tag:102];

    

    UITabBarItem * item4 = [[UITabBarItemalloc]initWithTitle:@"Movie"image:[UIImageimageNamed:@"msg_new"]tag:103];

   UIImage * img1ForItem5 = [UIImageimageNamed:@"start_top250"];// 未设置保持原色


    UIImage * img2ForItem5 = [[UIImageimageNamed:@"start_top250"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//保持原色,在图片初始化时实现

    

    

    

   UITabBarItem * item5 = [[UITabBarItemalloc]initWithTitle:@"9"image:img1ForItem5 selectedImage:img2ForItem5];

    //    NSBackgroundColorAttributeName

    // 用字典设置item5的字体颜色

    NSDictionary * dict =@{NSFontAttributeName:[UIFontsystemFontOfSize:18],NSForegroundColorAttributeName:[UIColoryellowColor]};

   // 设置高亮状态的字体及颜色

    [item5 setTitleTextAttributes:dictforState:UIControlStateHighlighted];

    

    

   NSArray * array = @[item1,item2,item3,item4,item5];

    

    

    tabBar.items = array;

    tabBar.selectedItem = array[0];//默认选中

    [self.viewaddSubview:tabBar];

}


- (void)_loadViews{

    

    UIView * view1 = [[UIViewalloc ]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];

    view1.backgroundColor = [UIColorredColor];

    view1.tag =200;

    UIView * view2 = [[UIViewalloc ]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height -49)];

    view2.backgroundColor = [UIColoryellowColor];

    view2.tag =201;

    UIView * view3 = [[UIViewalloc ]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];

    view3.backgroundColor = [UIColorblueColor];

    view3.tag =202;

    UIView * view4 = [[UIViewalloc ]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];

    view4.backgroundColor = [UIColorgreenColor];

    view4.tag =203;

    UIView * view5 = [[UIViewalloc ]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];

    view5.backgroundColor = [UIColorgrayColor];

    view5.tag =204;

    _view0 = [[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height -49)];

    [self.viewaddSubview:_view0];

    [_view0addSubview:view5];

    [_view0addSubview:view3];

    [_view0addSubview:view4];

    [_view0addSubview:view2];

    [_view0addSubview:view1];


    

    

    

    

}

#pragma mark - UITabBarDelegate

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{

   NSInteger tag = item.tag;

   UIView * view = [self.viewviewWithTag:tag+100];

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:1];

    [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:_view0cache:YES];

    [_view0bringSubviewToFront:view];

    

    [UIViewcommitAnimations];

    

}



- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)设置UITabBar自己为代理实现页面的动画转场(MS)

0 0
原创粉丝点击