zoukankan      html  css  js  c++  java
  • Container ViewController初探1

    今天调试程序遇到个问题,iOS7下在弹出Modal的子界面时,弹出层次不对,键盘和界面被分割在了Window的两侧,导致显示异常
    Presenting view controllers on detached view controllers is discouraged <HSRootViewController: 0x15dd248b0>.
    由于最上面的窗口是UIWindow,故考虑用addSubView的方式将ViewController.view添加上去了,自己维护ViewController的生存期就好了,但同时也发现了iOS很早就提供的ContainerViewController方式
    特此记录下
    https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

    Adding and Removing a Child
    Listing 14-1 shows a typical implementation that adds a view controller as a child of another view controller. Each numbered step in the listing is described in more detail following the listing.

    Listing 14-1 Adding another view controller’s view to the container’s view hierarchy
    - (void) displayContentController: (UIViewController*) content;
    {
    [self addChildViewController:content]; // 1
    content.view.frame = [self frameForContentController]; // 2
    [self.view addSubview:self.currentClientView];
    [content didMoveToParentViewController:self]; // 3
    }
    Here’s what the code does:

    It calls the container’s addChildViewController: method to add the child. Calling the addChildViewController: method also calls the child’s willMoveToParentViewController: method automatically.
    It accesses the child’s view property to retrieve the view and adds it to its own view hierarchy. The container sets the child’s size and position before adding the view; containers always choose where the child’s content appears. Although this example does this by explicitly setting the frame, you could also use layout constraints to determine the view’s position.
    It explicitly calls the child’s didMoveToParentViewController: method to signal that the operation is complete.
    Eventually, you want to be able to remove the child’s view from the view hierarchy. In this case, shown in Listing 14-2, you perform the steps in reverse.

    Listing 14-2 Removing another view controller’s view to the container’s view hierarchy
    - (void) hideContentController: (UIViewController*) content
    {
    [content willMoveToParentViewController:nil]; // 1
    [content.view removeFromSuperview]; // 2
    [content removeFromParentViewController]; // 3
    }

  • 相关阅读:
    【教程】模拟登陆百度之Java代码版
    Redis错误配置详解
    Redis内存存储结构分析
    Notepad++安装插件
    hadoop2.x 常用端口及定义方法
    微信订阅号可以开通微信支付吗?
    CDH 的Cloudera Manager免费与收费版的对比表
    Hadoop调度框架
    再谈spark部署搭建和企业级项目接轨的入门经验(博主推荐)
    Hive环境的安装部署(完美安装)(集群内或集群外都适用)(含卸载自带mysql安装指定版本)
  • 原文地址:https://www.cnblogs.com/decwang/p/4652068.html
Copyright © 2011-2022 走看看