自定义tabbar,点击中间按钮不切换页面,而是让当前的子视图控制器跳转到新页面。(类似新浪微博发布)...

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    /************************隐藏tabbar上的黑色线条***************************/
    CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setBackgroundImage:img];
    [self.tabBar setShadowImage:img];
    /************************隐藏tabbar上的黑色线条***************************/

    
    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
    item1.selectedImage = [[UIImage imageNamed:@"tabbar_home_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"" image:[[UIImage imageNamed:@"tabbar_order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
    UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"我的" image:[[UIImage imageNamed:@"tabbar_person"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
    item3.selectedImage = [[UIImage imageNamed:@"tabbar_person_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    
    NSArray *controllers = @[@"HomePage",@"Order",@"Person"];
    for (int i = 0; i < 3; i++) {
        Class cls = NSClassFromString([NSString stringWithFormat:@"%@ViewController",controllers[i]]);
        UIViewController *controller = (UIViewController *)[[cls alloc] init];
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:controller];
        nc.tabBarItem = @[item1,item2,item3][i];
        [self addChildViewController:nc];
    }
    
    
    UIImageView *tabbarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.tabBar.frame.size.height - 61, SCREEN_WIDTH, 61)];
    tabbarView.image = [UIImage imageNamed:@"tabbar"];
    [self.tabBar addSubview:tabbarView];
    
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (viewController == self.viewControllers[1]) {
        //点击中间tabbarItem,不切换,让当前页面跳转
        OrderViewController *order = [[OrderViewController alloc] init];
        order.hidesBottomBarWhenPushed = YES;
        [(UINavigationController *)tabBarController.selectedViewController pushViewController:order animated:YES];
        return NO;
    }
    return YES;
}

 

转载于:https://www.cnblogs.com/siasyl/p/5492957.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值