iOS小技巧·把子视图控制器的视图添加到父视图控制器

栏目: C · 发布时间: 5年前

内容简介:1. 把子视图控制器的视图添加到父视图控制器并覆盖2. 把子视图控制器的视图添加到父视图控制器的指定容器视图,适当时机跳转作者:陈满iOS

1. 把子视图控制器的视图添加到父视图控制器并覆盖

  • 添加子控制器

#pragma mark - 添加子控制器
- (void)addSubControllers{
  [self addChildViewController:_childViewController];
  [self.view addSubview:_childViewController.view];
  [_childViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.view);
  }];
}

2. 把子视图控制器的视图添加到父视图控制器的指定容器视图,适当时机跳转

  • 添加子控制器

#pragma mark - 添加子控制器
- (void)addSubControllers
{
    _childViewController = [[InfoViewController alloc] initWithNibName:NSStringFromClass([InfoViewController class]) bundle:nil];
    [self addChildViewController: _childViewController]; 
    _childViewController.sModel = self.sModel;
}
  • 跳转控制器

#pragma mark - 跳转控制器
- (void)gotoContentView
  [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  [self fitFrameForChildViewController:_childViewController];
  //设置默认显示在容器View的内容
  [self.contentView addSubview:_childViewController.view];
}
  • 子VC的布局约束

#pragma mark - 子VC的布局约束
- (void)fitFrameForChildViewController:(UIViewController *)chileViewController{
    CGRect frame = self.contentView.frame;
    frame.origin.y = 0;
    chileViewController.view.frame = frame;
}

作者:陈满iOS

链接:https://www.jianshu.com/p/06e334efc46e


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Is Parallel Programming Hard, And, If So, What Can You Do About

Is Parallel Programming Hard, And, If So, What Can You Do About

Paul E. McKenney

The purpose of this book is to help you understand how to program shared-memory parallel machines without risking your sanity.1 By describing the algorithms and designs that have worked well in the pa......一起来看看 《Is Parallel Programming Hard, And, If So, What Can You Do About 》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具