UINavigationController与UITabBarController相关问题

UINavigationController与UITabBarController相关问题

 

UINavigationController与UITabBarController混用是非常常见的,有时候会遇到UINavigationController推出(push)出controller后隐藏UITabBarController的问题,很容易对吧.

源码如下:

//
//  AppDelegate.m
//  NavigationController
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"

#define CreateNavigationControllerWith(controller) \
[[UINavigationController alloc] initWithRootViewController:controller]

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // 初始化导航栏控制器
    UINavigationController *newProductNC  = \
        CreateNavigationControllerWith([RootViewController new]);
    
    // 初始化TabBarController
    UITabBarController *rootBC = [[UITabBarController alloc] init];
    rootBC.viewControllers = @[newProductNC];
    
    // 交给系统管理
    self.window.rootViewController = rootBC;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end


//
//  RootViewController.m
//  NavigationController
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "RootViewController.h"
#import "SecondViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"YouXianMing";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 设定背景色
    self.view.backgroundColor = [UIColor whiteColor];

    // 点击手势
    UITapGestureRecognizer *tapGesture = \
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(tapEvent:)];
    
    // 添加手势
    [self.view addGestureRecognizer:tapGesture];
}

- (void)tapEvent:(UIGestureRecognizer *)sender
{
    [self.navigationController pushViewController:[SecondViewController new]
                                         animated:YES];
}

@end


//
//  SecondViewController.m
//  NavigationController
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

@end

效果:

将RootViewController.m中tapEvent:修改一下,如下所示:

效果(注意看底部的隐藏效果哦):

注意:隐藏与取消隐藏是成对出现的.

 

 

附录:

-修改系统颜色样式-

 

http://stackoverflow.com/questions/19504291/changing-the-tint-color-of-uibarbuttonitem

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值