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. 8.RabbitMQ 消息传递Java对象

    通过消息服务器传递Java对象,Java类必须实现序列化接口,可以把Java对象转化为字节数组,从消费者或生产者传递到另外一个JVM中,一定需要两个JVM共享这个类,比如是UserInfo类.   1 ...

  2. Instrumentation 实践详解

    原文地址:https://blog.csdn.net/pengjunlee/article/details/72717622

  3. ParameterizedThreadStart task

    using System;using System.Diagnostics;using System.Threading;using System.Threading.Tasks; namespace ...

  4. 初探分布式环境的指挥官ZooKeeper

    目录 1. 从单机到集群,分布式环境中的挑战 1.1 集中式的特点 1.2 集中式的痛点 1.3 从单体到SOA的转变 1.4 分布式服务总体框架 1.5 分布式应用概述 2. ZK基本概念及核心原理 ...

  5. linux下使用scp在服务器之间拷贝文件 (转载)

    CentOS, 本地服务器,ip: 192.168.1.111Ubuntu, 远程服务器,ip: 192.168.1.112 1.拷贝远程服务器的目录到本地服务器远程服务器192.168.1.112上 ...

  6. 注意:阿里Druid连接池监控的两个坑

    阿里的Druid大家都知道是最好的连接池,其强大的监控功能是我们追求的重要特性.但在实际情况中也有不少坑,说下最近遇到的一个坑吧! 问题1:不断打印error级别的错误日志 session ip ch ...

  7. 注意:字符串substring方法在jkd6,7,8中的差异。

    标题中的substring方法指的是字符串的substring(int beginIndex, int endIndex)方法,这个方法在jdk6,7是有差异的. substring有什么用? sub ...

  8. 2- SQL语句的强化

    查询类型cate_name为 '超极本' 的商品名称.价格 select name,price from goods where cate_name = '超级本'; 显示商品的种类 select c ...

  9. springboot中参数处理

    springboot1中处理是这样的 @Configuration public class WebConfig extends WebMvcConfigurerAdapter{ @Autowired ...

  10. java_函数式编程写法

    package cn.aikang.Test; import org.junit.Test; import java.util.Scanner; import java.util.function.S ...