zoukankan      html  css  js  c++  java
  • UIContainerView纯代码实现及原理介绍

    UIContainerView纯代码实现及原理介绍

    1.1-在StoryBoard中使用UIContainerView

    • 1.在storyboard中搜索UIContainerview并拖入到控制器中,设置约束

    这里写图片描述

    • 2.可以看到ContainerView自带一个segue连线的控制器,而这个Segue既不是Push跳转而不是Model跳转,而是Embed嵌入的形式

    这里写图片描述

    • 3.运行,可以看到右侧控制器的视图通过UIContainerView嵌入到左侧的控制器中

    这里写图片描述

    1.2-纯代码使用UIContainerView

    • 1.创建一个控制器,设置背景颜色为绿色

    这里写图片描述

    • 2.将Storyboard中的UIContainerView拖到代码时,会发现根本没有UIContainerview这个类,它的本质其实就是一个UIView 
      • 本人推测:它本质上应该是一个未开放的UIView的一个Category分类

    这里写图片描述

    • 3.纯代码实现UIContainerview

    这里写图片描述

    
    #import "ViewController.h"
    
    #import "SecondViewController.h"
    
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UIView *containerView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        [self addContainerView];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)addContainerView
    {
        //1.创建containerView目标控制器
        SecondViewController *second = [[SecondViewController alloc] init];
        //设置背景颜色
        second.view.backgroundColor = [UIColor greenColor];
        //2.将目标控制器的视图赋值给容器视图(不能用addSubView,否则设置frame无效)
        self.containerView = second.view;
        //设置显示大小
        self.containerView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-200);
        //3.添加到当前视图
        [self.view addSubview:self.containerView];
    
        //4.获取到Containerview的目标控制器
        NSLog(@"%@",self.containerView.nextResponder);
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    @end
    
    

    1.3-UIContainerview特点及原理分析

    • UIContainView是iOS系统中非常特殊的一个控件,它的主要特点如下:

      • (1)只能在Storyboard中搜索到UIContainerview,代码中没有这个类 
        • 应该是属于系统并未开放的UIView的分类
      • (2)是一个不能够被渲染的视图容器 
        • 不能被渲染,也就是说设置背景颜色backgroundColor和bounds属性等一些渲染属性是无效的
    • UIContainerview的原理

      • UIContainer通过强引用控制器的视图(赋值操作),再作为其他控制器的子视图,从而达到一个控制器中显示两个控制器视图的效果
     
    0
    转自:http://blog.csdn.net/u013263917/article/details/53487368
  • 相关阅读:
    c#多线程和Socket笔记
    Socket测试工具包的开发(TCP UDP)
    使用socket模拟服务器给客户端发消息
    AU3学习笔记
    c#委托与事件(三)
    c#委托与事件(二)
    使用的工具
    Zip 压缩问题件,获取真实扩展名
    PsExec使用
    socket 통신
  • 原文地址:https://www.cnblogs.com/feiyu-mdm/p/6588826.html
Copyright © 2011-2022 走看看