View-Controller-Containment
- willMove(toParentViewController:)
- 调用时机
- 调用
addChildViewController(_:)以钱会被自动调用 - 调用
removeFromParentViewController()之前被手动调用。
didMove(toParentViewController:)
- 调用时机
- 调用
removeFromParentViewController()方法之后被自动调用 - 调用
addChildViewController(_:)方法之后被手动调用。
把子vc的view加到父vc的view上
[self addChildViewController:_startMapViewController]; // 1 作为子VC,会自动调用子VC的willMoveToParentViewController方法。
[topContainer addSubview:_startMapViewController.view]; // 2 子VC的view被作为subview添加到第一个viewContainer中
[_startMapViewController didMoveToParentViewController:self]; // 3 子VC被通知拥有一个父VC。
把子VC的view移除
[fromController willMoveToParentViewController:nil];//
调用转场方法或者[fromController.view removeFromSuperView]
[fromController removeFromParentViewController]; //
5 transition(from:to:duration:options:animations:completion:)
This method adds the second view controller's view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller's view from the view hierarchy.
这个函数首先把第二个VC的view加到父vc的字view上,然后执行动画,最后把第一个vc的view从view hierarchy中移除。
{
toController.view.frame = fromController.view.bounds; // 1
[self addChildViewController:toController]; //
[fromController willMoveToParentViewController:nil]; //
[self transitionFromViewController:fromController
toViewController:toController
duration:0.2
options:direction | UIViewAnimationOptionCurveEaseIn
animations:nil
completion:^(BOOL finished) {
[toController didMoveToParentViewController:self]; // 2
[fromController removeFromParentViewController]; // 3
}];
}
这个函数是把fromVC及其View移除,toVC及其View加到界面上去。
fromVC移除
[fromController willMoveToParentViewController:nil]; //函数调用前
[fromController removeFromParentViewController]; // 动画block中
[fromController.view removeFromSuperView] //动画block之后
toVC加到界面上
[self addChildViewController:toController]; //函数调用前
[self.view addSubView:toController.view] //动画block之前
[toController didMoveToParentViewController:self]; // block之中
View-Controller-Containment的更多相关文章
- How to use view controller containment
https://www.hackingwithswift.com/example-code/uikit/how-to-use-view-controller-containment private f ...
- 【IOS笔记】View Controller Basics
View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...
- 组合View Controller时遇到的一点问题
View Controller的组合应用其实很常见了,比如说Tab bar controller和Navigation view controller的组合使用,像这种一般都是Navigation v ...
- View Controller Programming Guide for iOS---(三)---Using View Controllers in Your App
Using View Controllers in Your App Whether you are working with view controllers provided by iOS, or ...
- View Controller Programming Guide for iOS---(二)---View Controller Basics
View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ...
- iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)
这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...
- 报错:Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
原因分析:在StoryBoard中没有一个view controller设置了Initial Scene. 解决方案:在Storyboard中,选择一个view conroller作为story bo ...
- iOS架构师之路:控制器(View Controller)瘦身设计
前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...
- View Controller Relationships
Parent-child relationshipsParent-child relationships are formed when using view controller container ...
- Model View Controller
On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defau ...
随机推荐
- 【LA3713 训练指南】宇航员分组 【2-sat】
题意 有A,B,C三个任务要分配给n个宇航员,其中每个宇航员恰好要分配一个任务.设所有n个宇航员的平均年龄为x,只有年龄大于或等于x的宇航员才能分配任务A:只有年龄严格小于x的宇航员才能分配任务B,而 ...
- css3中的transform、transition、translate、animation(@keyframes)的区别
一.前言 在CSS中,我们经常会使用到transform.transition.translate.animation(@keyframes)这些长得相似,又不好区分的属性(值).每当需要使用它们,都 ...
- 花了好几个小时的奇葩Mat为0问题
问题 1. Mat mserMat = adaptive_image_from_points(contour, rect); CCharacter character; character.setCh ...
- Python一行代码搞定的事情
python -m SimpleHTTPServer 8000 http://127.0.0.1:8000/ 有了这一行代码分享本地盘内容就不需要FTP了. pydoc:Python文档工具 pyth ...
- 最大公约数(gcd)和 最小公倍数(lcm)——辗转相除法
辗转相除法(又称欧几里得算法)是求最大公因数的算法 要求a,b的最大公约数(a>b),我们可以递归地求b,a%b的最大公约数,直到其中一个数变成0,这时另一个数就是a,b的最大公约数. C++实 ...
- tp5 sql 大于小于
1.大于 $rwhere['ctime'] = array('egt',10000); 2.小于 $rwhere[);
- [JAVA] 小数转百分数
import java.text.NumberFormat; //获取格式化对象 NumberFormat format = NumberFormat.getPercentInstance(); // ...
- Lucene.Net(转)
出处:http://www.cnblogs.com/piziyimao/archive/2013/01/31/2887072.html 做过站内搜索的朋友应该对Lucene.Net不陌生,没做过的也许 ...
- [转]ubuntu linux下DNS重启后丢失(不是Network-manager造成的情况)
从网上得知 /etc/resolv.conf中的DNS配置是从/etc/resolvconf/resolv.conf.d/head中加载而来,所以每回改resolv.conf都会失效,在此文件里面已经 ...
- Selenium2+python自动化之数据驱动(ddt)
环境准备 1.安装ddt模块,打开cmd输入pip install ddt在线安装 数据驱动原理 1.测试数据为多个字典的list类型 2.测试类前加修饰@ddt.ddt 3.case前加修饰@ddt ...