除 UINavigationController 外最流行的 NavigationController!
心有猛虎,细嗅蔷薇。
效果参考 App:腾讯新闻、百度音乐等等
- 项目的根视图控制器是
LCNavigationController的实例。 LCNavigationController的实例的rootViewController是UITabBarController的实例。UITabBarController的实例的viewController是各个不同的控制器,也即各个标签页。- 导航栏:
LCNavigationController并没有导航栏,你可以选择在LCNavigationController和viewController中再加一层UINavigationController(仅使用其导航栏),也可以像 Demo 中那样,自定义一个导航栏 (继承自UIView,在上面放控件)。
-
- 方法一:CocoaPods 导入:
pod 'LCNavigationController' - 方法二:导入
LCNavigationController文件夹到你的项目中 (文件夹在 Demo 中可以找到)
- 方法一:CocoaPods 导入:
-
在
AppDelegate.m中,#import "LCNavigationController.h",参考如下代码:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; [self.window makeKeyAndVisible]; UIViewController *mainVC = [UIStoryboard storyboardWithName:@"Main" bundle:nil].instantiateInitialViewController; mainVC.tabBarItem.title = @"首页"; UIViewController *avc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AVC"]; avc.tabBarItem.title = @"发现"; UITabBarController *tabbar = [[UITabBarController alloc] init]; tabbar.viewControllers = @[mainVC, avc]; LCNavigationController *navC = [[LCNavigationController alloc] initWithRootViewController:tabbar]; self.window.rootViewController = navC; return YES; }
-
在你需要用到的地方
#import "LCNavigationController.h",然后:// 1. Push UIViewController *childVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"TwoVC"]; [self.lcNavigationController pushViewController:childVC]; // 2. Pop [self.lcNavigationController popViewController]; // 3. Pop to rootViewController [self.lcNavigationController popToRootViewController];
-
可自定义的参数(在
LCNavigationController.m中):static const CGFloat LCAnimationDuration = 0.50f; // Push / Pop 动画持续时间 static const CGFloat LCMaxBlackMaskAlpha = 0.80f; // 黑色背景透明度 static const CGFloat LCZoomRatio = 0.90f; // 后面视图缩放比 static const CGFloat LCShadowOpacity = 0.80f; // 滑动返回时当前视图的阴影透明度 static const CGFloat LCShadowRadius = 8.00f; // 滑动返回时当前视图的阴影半径
-
搞定!
- 提供配合
UITabBarController使用的 Demo。
- 更新自定义参数。
- 初始化提交。
- 发现问题请 Issues 我,谢谢:-)
- Email: [email protected]
- Blog: http://www.leodong.com
本项目采用 MIT license 开源,你可以利用采用该协议的代码做任何事情,只需要继续继承 MIT 协议即可。

