有時(shí)候會(huì)很迷惑的為什么我們找不到UIContainerview這個(gè)類.而在sb中我們會(huì)發(fā)現(xiàn)containView會(huì)自帶一個(gè)控制器.經(jīng)過個(gè)人的一些觀察發(fā)現(xiàn),實(shí)際上contaiView就是一個(gè)View.
TwoViewController *vc = [[TwoViewController alloc] init];
vc.view.backgroundColor = [UIColor redColor];
self.containView = vc.view;
self.containView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 200);
[self.view addSubview:self.containView];
實(shí)際上他的原理就是:
UIContainer通過強(qiáng)引用控制器的視圖(賦值操作),再作為其他控制器的子視圖,從而達(dá)到一個(gè)控制器中顯示兩個(gè)控制器視圖的效果.