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. Ubuntu 14.04 安装QQ2015

    作为重要的技术交流工具,Ubuntu下没有QQ还是挺不方便的. 参考链接(带软件下载链接)http://www.longene.org/forum/viewtopic.php?f=6&t=30 ...

  2. GDB调试教程

    简介 GDB(GNU debugger)是GNU开源组织发布的一个强大的UNIX下的程序调试工具.可以使用它通过命令行的方式调试程序.它使你能在程序运行时观察程序的内部结构和内存的使用情况.你也可以使 ...

  3. 清北学堂 day6 兔子

    ---恢复内容开始--- [问题描述] 在一片草原上有N个兔子窝,每个窝里住着一只兔子,有M条路径连接这些窝.更特殊地是,至多只有一个兔子窝有3条或更多的路径与它相连,其它的兔子窝只有1条或2条路径与 ...

  4. maven 引用本地jar

    1.添加lib文件夹在src文件夹中.2.拷贝所需要的test.jar包到lib文件夹.3.在pom文件加入如下依赖 <!--添加本地私有包--><dependency> &l ...

  5. 五)使用 easyui-tabs 遭遇错误 Unexpected Exception caught setting '_' on

    十月 10, 2015 3:08:35 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error 严重: Developer ...

  6. react+webpack基础学习配置

    最近学习react,公司的项目是使用create-react-app来搭建的,而我想重新使用node+mysql+react来搭建一个新的博客. 今天尝试从零开始搭建一个webpack+react项目 ...

  7. TunnelBroker for EdgeRouter 后记

    最近入手了UBNT EdgeRouter X, 想着用 IPv6在路由上FQ,经过两天折腾,终于正常使用,留下点标记 供后来同学借鉴. TUNNEL的注册和配置,可以完全按这篇文章来: TunnelB ...

  8. sqlite数据库的char,varchar,text,nchar,nvarchar,ntext的区别(转)

    sqlite数据库存储table1.CHAR.CHAR存储定长数据很方便,CHAR字段上的索引效率级高,比如定义char(10),那么不论你存储的数据是否达到了10个字节,都要占去10个字节的空间,不 ...

  9. C# WPF Application 下的文件操作

    好气哦,电脑好烂,每天花大把的时间在等电脑反应上. 没有钱买新电脑,连组台式机的钱都没有.好气哦. 啊啊啊啊文件操作是什么鬼???C++下我都懵了,C#下好多东西要学!!!我不会!我不会!我不会!!! ...

  10. uwsgi启动提示:probably another instance of uWSGI is running on the same address (:8002). bind(): Address already in use [core/socket.c line 769]

    提示8002端口被占用,可以这样终止掉后再启动 sudo fuser -k 8002/tcp