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

UINavigationController与UITabBarController相关问题的更多相关文章

  1. UIViewController、UINavigationController与UITabBarController的整合使用

    UINavigationController与UITabBarController是iOS开发中最常用的两种视图控制器,它们都属于UIViewController的子类,继承关系如下: @interf ...

  2. iOS开发——实战OC篇&环境搭建之Xib(玩转UINavigationController与UITabBarController)

    iOS开发——实战OC篇&环境搭建之Xib(玩转UINavigationController与UITabBarController)   前面我们介绍了StoryBoard这个新技术,和纯技术 ...

  3. iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)

    iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)   这里我们就直接上实例: 一:新建一个项目singleV ...

  4. iOS开发——实战OC篇&环境搭建之StoryBoard(玩转UINavigationController与UITabBarController)

      环境搭建之StoryBoard(玩转UINavigationController与UITabBarController)   研究了这么就IOS开发,都没有所处一个像样或者自己忙一点的项目.最近自 ...

  5. UINavigationController和UITabBarController

    UINavigationController和UITabBarController 目录 概述 UINavigationController UITabBarController 实用功能 待解决 概 ...

  6. UINavigationController与UITabbarController的样式

    之前虽然也手写过这两中视图控制器,但是更多的还是使用SB来创建,最近发现了一些问题,现在总结一下. 1.改变UINavigationBar的颜色 在UINavigationController中,之前 ...

  7. UINavigationController 与 UITabBarController

    http://www.cnblogs.com/YouXianMing/p/3756904.html // index start from 1. UITabBarItem *newsItem = [[ ...

  8. UINavigationController  和 UITabBarController

    UINavigationController当设置根控制器的时候,意思就是把根控制器压入栈内,当我们push的时候,我们把下一个控制器压入栈内,当我们pop的时候把上面的控制器的内存释放   UITa ...

  9. UINavigationController和UITabBarController合用

    一.创建一个 Tabbed Application.默认创建的是带有两个Tab的工程. 二.在AppDelegate.h里面添加 @property (strong, nonatomic) UINav ...

随机推荐

  1. kibana-1-安装

    由于es5.2版本对head的插件支持不如2.4 安装挺麻烦, 于是选用kibana 关于5.2安装head插件可见这个博客 http://www.cnblogs.com/xing901022/p/6 ...

  2. [中英对照]Linux kernel coding style | Linux内核编码风格

    Linux kernel coding style | Linux内核编码风格 This is a short document describing the preferred coding sty ...

  3. 面试:C/C++常见库函数实现

    1. void *mymemcpy(void *dest, const void* src, size_t n): 内存拷贝函数,memcpy函数的功能是从源src所指的内存地址的起始位置开始拷贝n个 ...

  4. 用java实现一个简易编译器1-词法解析入门

    本文对应代码下载地址为: http://download.csdn.net/detail/tyler_download/9435103 视频地址: http://v.youku.com/v_show/ ...

  5. 深入了解Java虚拟机(3-1)虚拟机类加载机制

    虚拟机类加载机制 一.类加载的阶段和时机 1.阶段 整个生命周期包括:加载(Loading).验证(Verification).准备(Preparation).解析(Resolution).初始化(I ...

  6. split函数和merge函数

    split函数的主要功能是把一个彩色图像分割成3个通道,方便进一步的图像处理,具体说明如下: split Divides a multi-channel array into several sing ...

  7. MVC下拉框Html.DropDownList 和DropDownListFor 的常用方法

    一.非强类型:Controller:ViewData["AreId"] = from a in Table                               select ...

  8. spring boot 学习入门篇【spring boot项目的搭建以及如何加载jsp界面】

    [ 前言]  Spring Boot 简介:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置, ...

  9. Linux安装jdk,编写helloworld程序

    今天学习了Linux安装jdk,做个笔记记录一下. 第一步,确定Linux是32位的还是64位的,然后到oracle官网上下载对应版本的jdk,一般下载.tar.gz文件.查看Linux的版本的命令是 ...

  10. Emscripten编译环境搭建--将C和C++编译成JS

    Emscripten编译环境搭建--将C和C++编译成JS 需求:linux环境下用js执行c.c++文件,使用emscirpten编译器 目标:搭建好Emscripten环境 环境:Ubuntu16 ...