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

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott、Darron Schall、Keith Peters / Adobe Dev Library / 2006-10-11 / GBP 28.50

Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs......一起来看看 《ActionScript 3.0 Cookbook》 这本书的介绍吧!

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

URL 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具