UITabBarController+UINavigationController多层嵌套
2016-06-17 16:27
501 查看
来自会员z304983615的分享:
网上有海量的关于创建UITabBarController实例的代码,不过99%都是在AppDelegate中创建并作为App的根视图。但是,并不见得UITabBarController就一定要作为App的根视图存在。下面提供的这个demo就是在某个视图控制器中创建出来的(且标签的viewControllers全都是导航栏控制器),并且该视图控制器将做为一个UINavigationController的rootViewController,然后将这个UINavigationController的view加到其他别的视图控制器的view中。从而实现了RT所述的UINavigationController+UITabBarController多层嵌套。
不过,在UI上有个小Bug,就是显示出来的标签栏控制器的view会下移一段状态栏的高度。楼主为这个真是百思不得其解阿。 但是,最后设置了UITabBarController的view的frame为(0,-20,320,480)才将问题解决(设置为(0,0,320,460)不能解决问题)。
下面是部分代码
用UINavigationController嵌套带有UITabBarController的视图控制器:
-(void)viewDidLoad
{
[super viewDidLoad];
if (mainNav == nil) {
MainViewController *mainViewController = [[MainViewControlleralloc] initWithNibName:nil bundle:nil];
mainNav = [[UINavigationController alloc]initWithRootViewController:mainViewController];
[mainViewController release];
}
mainNav.view.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
mainNav.view.backgroundColor= [UIColor blackColor];
[self.view addSubview:mainNav.view];
}
实例化UITabBarController:
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden= YES;
if (tabBarCon == nil) {
tabBarCon = [[UITabBarController alloc] init];
FirstViewController *firstViewController =[[FirstViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *firstNav =[[UINavigationController alloc]initWithRootViewController:firstViewController];
SecondViewController *secondViewController =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *secondNav =[[UINavigationController alloc]initWithRootViewController:secondViewController];
tabBarCon.viewControllers = [NSArrayarrayWithObjects:firstNav,secondNav, nil];
}
/*******************************************************************************************************/
tabBarCon.view.frame= CGRectMake(0.0, -20.0, 320.0, 480.0);//
这句很关键,不加这句将会有一段状态栏高度的空白区域
/*******************************************************************************************************/
[self.view addSubview:tabBarCon.view];
}
附demo:
/cms/uploads/soft/130830/4196-130S0161214.zip |
原帖:http://www.cocoachina.com/bbs/read.php?tid=140083
CocoaChina是全球最大的苹果开发中文社区,官方微信每日定时推送各种精彩的研发教程资源和工具,介绍app推广营销经验,最新企业招聘和外包信息,以及Cocos2d引擎、CocosStudio开发工具包的最新动态及培训信息。关注微信可以第一时间了解最新产品和服务动态,微信在手,天下我有!
请搜索微信号“CocoaChina”关注我们!
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程
- 浅析iOS应用开发中线程间的通信与线程安全问题
- iOS中的UIKeyboard键盘视图使用方法小结
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法