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