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 ...
随机推荐
- 【LA2957 训练指南】运送超级计算机【二分,最大流】
题意: 宇宙中有n个星球,你的任务是用最短的时间把k个超级计算机从星球S运送到星球T.每个超级计算机需要一整艘飞船来运输.行星之间有m条双向隧道,每条隧道需要一整天的时间来通过,且不能有两艘飞船同时使 ...
- php static 变量声明
<?phpfunction test($key){ static $array = array(); /* 静态变量是只存在于函数作用域中的变量,注释:执行后这种变量不会丢失(下次调用这个函数 ...
- eclipse基础环境配置和svn、maven的配置以及maven的安装
安装eclipse和基础配置 第一步:解压eclipse安装包,直接解压就可以,绿色版安装 第二步:启动eclipse,注意这里的eclipse需要依赖jdk,并且版本需要匹配,否则启动会出 现问题. ...
- Openssl rsautl命令
一.简介 rsautl指令能够使用RSA算法签名,验证身份,加密/解密数据 二.语法 openssl rsautl [-in file] [-out file] [-inkey file] [-pas ...
- CSS块级元素、内联元素概念[转]
CSS文档流与块级元素(block).内联元素(inline),之前翻阅不少书籍,看过不少文章, 看到所多的是零碎的CSS布局基本知识,比较表面.看过O'Reilly的<CSS权威指南>, ...
- 如何注册facebook应用
最近项目中要做第三方登录,其中就有facebook的,下面讲解一下如何在facebook中创建应用 1.登录facebook的开发者平台(https://developers.facebook.com ...
- java Concurrent包学习笔记(二):CountDownLatch和CyclicBarrier
一.CountDownLatch CountDownLatch一个线程同步的工具,是的一个或者多个线程等待其他线程操作完成之后再执行. CountDownLatch通过一个给定的数值count来进行初 ...
- MyBatis和Hibernate相比较
作者:乌拉拉链接:http://www.zhihu.com/question/21104468/answer/58579295 1.开发对比开发速度 Hibernate的真正掌握要比Mybatis来得 ...
- hydra(九头蛇)多协议暴力破解工具
一.简介 hydra(九头蛇)全能暴力破解工具,是一款全能的暴力破解工具,使用方法简单 二.使用 使用hydra -h 查看基本用法 三.命令 hydra [[[-l LOGIN|-L FILE] [ ...
- (转)走进AngularJs(六) 服务
原文地址:http://www.cnblogs.com/lvdabao/p/3464015.html 今天学习了一下ng的service机制,作为ng的基本知识之一,有必要做一个了解,在此做个笔记记录 ...