码迷,mamicode.com
首页 > 其他好文 > 详细

UINavigationController与UITabBarController相关问题

时间:2014-05-30 07:16:51      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

UINavigationController与UITabBarController相关问题

bubuko.com,布布扣

 

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

bubuko.com,布布扣

bubuko.com,布布扣

源码如下:

bubuko.com,布布扣
//
//  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
bubuko.com,布布扣
bubuko.com,布布扣
//
//  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
bubuko.com,布布扣
bubuko.com,布布扣
//
//  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
bubuko.com,布布扣

效果:

bubuko.com,布布扣

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

bubuko.com,布布扣

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

bubuko.com,布布扣

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

 

 

附录:

-修改系统颜色样式-

bubuko.com,布布扣

bubuko.com,布布扣bubuko.com,布布扣

 

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

 

 

UINavigationController与UITabBarController相关问题,布布扣,bubuko.com

UINavigationController与UITabBarController相关问题

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/YouXianMing/p/3756904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!