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

private func add(asChildViewcontroller viewController: UIViewController){

// Add Child View Controller

addChild(viewController)

// Add Child View as Subview

view.addSubview(viewController.view)

// Configure Child View

viewController.view.frame = view.bounds

viewController.view.autoresizingMask = [.flexibleWidth,.flexibleHeight]

// Notify Child View Controller

viewController.didMove(toParent: self)

}

private func move(asChildViewcontroller viewController: UIViewController){

// Notify Child View Controller

viewController.willMove(toParent: self)

// Remove Child View From Superview

viewController.view.removeFromSuperview()

// Notify Child View Controller

viewController.didMove(toParent: self)

}

How to use view controller containment的更多相关文章

  1. 【IOS笔记】View Controller Basics

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

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

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

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

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

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

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

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

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

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

  8. View Controller Relationships

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

  9. Model View Controller

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

随机推荐

  1. NX二次开发-获取当前part所在路径UF_PART_ask_part_name

    #include <uf.h> #include <uf_ui.h> #include <uf_part.h> #include <atlstr.h> ...

  2. C++从string中删除所有的某个特定字符【转载】

    转载自https://www.cnblogs.com/7z7chn/p/6341453.html C++中要从string中删除所有某个特定字符, 可用如下代码 str.erase(std::remo ...

  3. [Nowcoder] 数数字

    题意:...咕咕懒得写了. 思路: 裸的记搜... #include <bits/stdc++.h> using namespace std; #define ll long long m ...

  4. 牛客多校第十场 H Stammering Chemists 判断图同构

    题意: 给出一个无向图,表示一种有机物质的结构式,问你这个有机物质是列表中的哪个. 题解: 判断图同构需要枚举全排列以对应点,但是此题中几乎只需要将点度数排序后一个一个比较,对于甲基位置再加个特判即可 ...

  5. 拾遗:Perl 正则表达式

    三种正则模式: 匹配:m//,其中前缀 m 可省略 替换:s/// 转化:tr/// 操作符: =~:存在匹配项则返回结果 !~:不存在匹配项则返回结果 修饰符: i:忽略大小写,如:s/.../.. ...

  6. KNN与决策树

    KNN: 就是计算特征之间的距离,某一个待预测的数据分别与已知的所有数据计算他们之间的特征距离,选出前N个距离最近的数据,这N个数据中哪一类的数据最多,就判定待测数据归属哪一类. 假如N=3,图中待测 ...

  7. JDBC_入门及注入问题

    .JDBC基本概念: java database Connectivity java数据库连接,java语言操作数据库 本质: 官方定义的一套操作所有关系型数据库的规则,即接口. 各个数据库厂商实现这 ...

  8. Python学习笔记(三)——文件系统中的常用方法

    OS模块中关于文件/目录常用的函数使用方法 函数名 使用方法 getcwd() 返回当前工作目录 chdir() 改变工作目录 listdir(path='.') 列举指定目录中的文件名('.'表示当 ...

  9. dubbo重连机制会不会造成错误

    dubbo在调用服务不成功时,默认会重试2次. Dubbo的路由机制,会把超时的请求路由到其他机器上,而不是本机尝试,所以 dubbo的重试机器也能一定程度的保证服务的质量. 但是如果不合理的配置重试 ...

  10. 数据库MySQL--基础查询

    1.查询字段 查询表某字段:select 字段名 from 表名: 查询表内所有字段:select * from 表名: (当字段和关键字重名是用( ` )着重号区分 ) 2.查询常量值 select ...