Container ViewController初探1
今天调试程序遇到个问题,iOS7下在弹出Modal的子界面时,弹出层次不对,键盘和界面被分割在了Window的两侧,导致显示异常
Presenting view controllers on detached view controllers is discouraged <HSRootViewController: 0x15dd248b0>.
由于最上面的窗口是UIWindow,故考虑用addSubView的方式将ViewController.view添加上去了,自己维护ViewController的生存期就好了,但同时也发现了iOS很早就提供的ContainerViewController方式
特此记录下
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html
Adding and Removing a Child
Listing 14-1 shows a typical implementation that adds a view controller as a child of another view controller. Each numbered step in the listing is described in more detail following the listing.
Listing 14-1 Adding another view controller’s view to the container’s view hierarchy
- (void) displayContentController: (UIViewController*) content;
{
[self addChildViewController:content]; // 1
content.view.frame = [self frameForContentController]; // 2
[self.view addSubview:self.currentClientView];
[content didMoveToParentViewController:self]; // 3
}
Here’s what the code does:
It calls the container’s addChildViewController: method to add the child. Calling the addChildViewController: method also calls the child’s willMoveToParentViewController: method automatically.
It accesses the child’s view property to retrieve the view and adds it to its own view hierarchy. The container sets the child’s size and position before adding the view; containers always choose where the child’s content appears. Although this example does this by explicitly setting the frame, you could also use layout constraints to determine the view’s position.
It explicitly calls the child’s didMoveToParentViewController: method to signal that the operation is complete.
Eventually, you want to be able to remove the child’s view from the view hierarchy. In this case, shown in Listing 14-2, you perform the steps in reverse.
Listing 14-2 Removing another view controller’s view to the container’s view hierarchy
- (void) hideContentController: (UIViewController*) content
{
[content willMoveToParentViewController:nil]; // 1
[content.view removeFromSuperview]; // 2
[content removeFromParentViewController]; // 3
}
Container ViewController初探1的更多相关文章
- iOS UIKit:viewController之动画(5)
当弹出一个view controller时,UIKit提供了一些标准转换动画,并且也支持用户自定义的动画效果. 1 UIView动画 UIView是自带动画实现功能,其中有两种方式实现: ...
- UITabBarController详解
UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程序,ipod程序等.UITabBarControl ...
- 0122——UITabBarController
UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...
- UITabBarController+微博简单模拟1
UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...
- UITabBarController使用详解
UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程序,ipod 程序等.UITabBarController通常作为整个程序的rootViewCo ...
- IOS开发 UITabBarController
UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程 序,ipod程序等.UITabBarContro ...
- 在UIViewController中获得Container View里的embed viewController的引用
When you want to use a controller you use the UIStoryboard method instantiateViewControllerWithIdent ...
- 【iOS】iOS它Container View获得ViewController
近期使用Container View来在主View Controller建立自己的子Controller,但是遇到问题.不知道怎样用代码获取Controller View附带的View Control ...
- 容器安全拾遗 - Rootless Container初探
摘要: Docker和Kubernetes已经成为企业IT架构的基础设施,安全容器运行时越来越被关注.近期Docker 19.03中发布了一个重要的特性 “Rootless Container”,在提 ...
随机推荐
- HDU 1828 扫描线(矩形周长并)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 二模 (6) day1
第一题: 设 S(N)表示 N 的各位数字之和,如 S(484)=4+8+4=16,S(22)=2+2=4.如果一个正整数 x满足 S(x*x)=S(x)*S(x),我们称 x 为 Rabbit Nu ...
- C#winform省市县联动,以及有的县是空值时显示异常的处理
一.如下comboBox1.comboBox2.comboBox3,原来这三个都是空的, 将数据库中的省份传递到comboBox1中 我的数据库有parent字段,根据市的parent找到省,根据县的 ...
- Spring对jdbc的支持
Spring对jdbc技术提供了很好的支持. 体现在: 1)Spring对c3p连接池的支持很完善: 2)Spring对jdbc提供了JdbcTemplate,来简化jdbc操作: 1.使用步骤 1) ...
- Android 之 JSON操作
Android默认已经集成了操作JSON相关的API,如下所示: 也可以不使用JSON工具类,直接使用字符串拼接. 注意:可以使用字符串来构造JSONArray和JSONObject,这就是JSON解 ...
- JS获取上传文件的名称、格式、大小
<input id="File1" type="file" onchange="checkFile(this)" /> 方式一) ...
- redis——基础介绍
转自:http://www.cnblogs.com/xing901022/p/4863929.html 1 什么是Redis Redis(REmote DIctionary Server,远程数据字典 ...
- MongoDB 语法(转)
Mongod.exe 是用来连接到mongo数据库服务器的,即服务器端. Mongo.exe 是用来启动MongoDB shell的,即客户端. 其他文件: mongodump 逻辑备份工具. mon ...
- hadoop2.x通过Zookeeper来实现namenode的HA方案以及ResourceManager单点故障的解决方案
我们知道hadoop1.x之前的namenode存在两个主要的问题:1.namenode内存瓶颈的问题,2.namenode的单点故障的问题.针对这两个问题,hadoop2.x都对它进行改进和解决.其 ...
- 针对初学者的A*算法入门详解(附带Java源码)
英文题目,汉语内容,有点挂羊头卖狗肉的嫌疑,不过请不要打击我这颗想学好英语的心.当了班主任我才发现大一18本书,11本是英语的,能多用两句英语就多用,个人认为这样也是积累的一种方法. Thanks o ...