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. PHP ftp_rename() 函数

    定义和用法 ftp_rename() 函数重命名 FTP 服务器上的文件或目录. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_rename(ftp_connectio ...

  2. 思维题——牛客多校第六场D

    这题的不能用二分做,因为不满足单调性的 可以用multiset做 #include<bits/stdc++.h> #define ll long long #define rep(i,a, ...

  3. fastJson中常用方法以及遇到的“坑”

    1.使用fastJson,首先引入fastJson依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> & ...

  4. NX二次开发-UFUN由工程图视图tag获取图纸页tag UF_DRAW_ask_drawing_of_view

    #include <uf.h> #include <uf_draw.h> #include <uf_drf.h> #include <uf_obj.h> ...

  5. 20180713NOIP模拟赛

    20180713NOIP模拟赛 T1:动物园 zoo.cpp 2s [题目描述] 给定一张图,点有点权,求每个点到其他所有点中所有点的权值最小值之和. [思路] \(50pts\)做法:对于每个点跑一 ...

  6. hdu多校第十场 1003 (hdu6693) Valentine's Day 贪心/概率

    题意: 有许多物品,每个物品有一定概率让女朋友开心.你想让女朋友开心且只开心一次,让你挑一些物品,使得这个只开心一次的概率最大,求最大概率. 题解: 设物品i让女朋友开心的概率为$p_i$ 若你挑选了 ...

  7. sql准确判断某个ip

    问题:如图 当我执行sql要准确查找某个IP是属于哪个库室时候,我刚开始是这样写的 select * from Definition_Read_Room where HFIP like '%172.2 ...

  8. 2-MySQL高级-事务-基本概念(1)

    事务 1. 为什么要有事务 事务广泛的运用于订单系统.银行系统等多种场景 例如: A用户和B用户是银行的储户,现在A要给B转账500元,那么需要做以下几件事: 检查A的账户余额>500元: A ...

  9. springboot中参数校验

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  10. 解决OCX 在 非开发电脑上注册出错的问题

    这几天遇到一个问题,就是在我自己电脑上开发的OCX 放在其他电脑上居然注册失败,管理员运行也不行,老是会蹦出这样的错误,最后呢终于让我找到一个线索就是在开发电脑上可以安装,在无开发环境上很大概率安装失 ...