Contrainer View storyboard 能拖出來的控件逗余,繼承UIView录粱,當(dāng)又與UIStackView 不一樣,很奇葩的東西啥繁。
注1:可以直接拖入某個(gè)ViewController青抛,并且可以多個(gè)!每一個(gè)對(duì)應(yīng)連接了一個(gè)VC,相當(dāng)于add childViewController了!
注2:鏈接有segue蚕钦,但是不能直接用會(huì)崩潰,也不知道該怎么用才好罪帖。
注3:現(xiàn)在只能遍歷自身的childViewControllers邮屁,然后去切換,感覺并沒有純代碼方便啊坐昙,阿西吧芋忿。
// 找到對(duì)應(yīng)的 childViewController(總覺得哪里不對(duì)!1韵伞Q沉恕!)
- (void)checkChildViewController {
[self.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[AViewController class]]) {
self.avc = obj;
}
else if ([obj isKindOfClass:[BViewController class]]) {
self.bvc = obj;
}
else if ([obj isKindOfClass:[CViewController class]]) {
self.cvc = obj;
self.currendViewController = obj;// 最后一個(gè)拖進(jìn)去的 container View 是當(dāng)前的
}
else {
// if more vc
}
}];
}
// 切換
- (void)transitionToViewController:(UIViewController *)destinationViewController {
if (destinationViewController == self.currendViewController) {
return;
}
[self transitionFromViewController:self.currendViewController toViewController:destinationViewController duration:CGFLOAT_MIN options:UIViewAnimationOptionCurveEaseOut animations:^{
} completion:^(BOOL finished) {
self.currendViewController = destinationViewController;
}];
}
順便貼個(gè)純代碼的
self.viewControllers = @[self.detailViewController,
self.performanceViewController,
self.relatedDocumentViewController,
self.similarProductViewController,
self.productAboutViewController];
- (void)addChildViewControllers {
int temp = 0;
for (UIViewController *viewController in self.viewControllers) {
[self addChildViewController:viewController];
[viewController didMoveToParentViewController:self];
viewController.view.frame = self.contentView.bounds;
if (temp == 0) {
[self.contentView addSubview:viewController.view];
self.currentViewController = viewController;
}
temp ++;
}
}
- (void)transitionViewControlleToIndex:(NSInteger)index {
if (index >= self.viewControllers.count) {
return ;
}
UIViewController *transitionedController = self.viewControllers[index];
if (transitionedController != self.currentViewController) {
[self transitionFromViewController:self.currentViewController
toViewController:transitionedController
duration:CGFLOAT_MIN
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
//
} completion:^(BOOL finished) {
self.currentViewController = transitionedController;
}];
}
}
1