1. willMove(toParentViewController:)

    • 调用时机
    • 调用addChildViewController(_:)以钱会被自动调用
    • 调用removeFromParentViewController()之前被手动调用。
  2. didMove(toParentViewController:)

    • 调用时机
    • 调用removeFromParentViewController()方法之后被自动调用
    • 调用addChildViewController(_:)方法之后被手动调用。
  3. 把子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。
  4. 把子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

View-Controller-Containment的更多相关文章

  1. How to use view controller containment

    https://www.hackingwithswift.com/example-code/uikit/how-to-use-view-controller-containment private f ...

  2. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  3. 组合View Controller时遇到的一点问题

    View Controller的组合应用其实很常见了,比如说Tab bar controller和Navigation view controller的组合使用,像这种一般都是Navigation v ...

  4. 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 ...

  5. 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 ...

  6. iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)

    这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...

  7. 报错: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 ...

  8. iOS架构师之路:控制器(View Controller)瘦身设计

    前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...

  9. View Controller Relationships

    Parent-child relationshipsParent-child relationships are formed when using view controller container ...

  10. Model View Controller

    On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defau ...

随机推荐

  1. HRESULT:0x80070057 (E_INVALIDARG)

    笔记本蓝屏后,在vs2010中调试项目时出现该异常, 解决方法:清空C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Fi ...

  2. U3D OnDrawGizmos

    private void OnDrawGizmos() { Debug.Log("OnDrawGizmos"); Gizmos.DrawWireSphere(this.transf ...

  3. Struts2常量详解

    -----------------siwuxie095 Struts2 常量详解 Struts2 的常量大多在默认的配置文件中已经配置好,但根据 用户需求和开发要求的不同,可能需要修改这些常量值,修改 ...

  4. 监控服务器cpu、磁盘、模板以及自定义key

    一.检测主机存活 net.tcp.service.perf[tcp,,] Float型 返回0代表端口挂了 zabbix fping要开启sudo权限之类比较不方便 二.监控CPU负载 监控load ...

  5. Python OCR提取普通数字图形验证中的数字

    截取图形验证码: # -*- coding: UTF-8 -*- ''' Created on 2016年7月4日 @author: xuxianglin ''' import os import t ...

  6. 实践作业4---DAY3阶段二。

    第二阶段是用户调研,我们小组选择了一个5班的同学,作为采访对象.采访比较详实,但是样本太少,不太有说服力. 具体采访详情如下: 问:请问您使用喜欢发表Blog么? 答:肯定有啊. 问:都用什么网站发表 ...

  7. Thinkphp 导出csv 先存储在服务器,然后输出链接下载

    public function exportQiandao() { // header("Content-type:text/html;charset=gb2312"); ini_ ...

  8. 更改oracle数据库字符集

    A.oracle server 端 字符集查询  select userenv('language') from dual 其中NLS_CHARACTERSET 为server端字符集 NLS_LAN ...

  9. STL 中的map 与 hash_map的理解

    可以参考侯捷编著的<STL源码剖析> STL 中的map 与 hash_map的理解 1.STL的map底层是用红黑树存储的,查找时间复杂度是log(n)级别: 2.STL的hash_ma ...

  10. NIOS II SOPC系统自定义IP常见知识点总结

    封装IP1.将写好的Verilog代码添加在Quartus工程中,IP目录下,(如果没有,自己建一个)2.打开Qsys工具,选择New Component3.name和Display name输入合理 ...