addChildViewController
来源:互联网 发布:天猫双11晚会网络直播 编辑:程序博客网 时间:2024/05/21 21:01
1:设置三个vc,设置当前父视图的contentView为第三个的view;
设置中间变量 self.currentVC = thirdVC;
2:点击
如果是当前VC,则不发生变化;
否则进行以下操作;
将当前vc记录以下,记录为oldVC,
[self transitionFromViewController:self.currentVC toViewController:firstVC duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
} completion:^(BOOL finished) {
if (finished) {
self.currentVC = firstVC;
}else{
self.currentVC = oldVC;
}
}];
如果没有加载完,则self.currentVC = oldVC;,如果加载完,就显示self.currentVC = firstVC;
3:demo代码如下:
#import "ViewController.h"
#import "FirstVC.h"
#import "SecondVC.h"
#import "ThirdVC.h"
@interface ViewController (){
FirstVC *firstVC;
SecondVC *secondVC;
ThirdVC *thirdVC;
}
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (nonatomic, strong) UIViewController * currentVC;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
firstVC = [[FirstVC alloc] init];
secondVC = [[SecondVC alloc] init];
thirdVC = [[ThirdVC alloc] init];
[self addChildViewController:firstVC];
[self addChildViewController:secondVC];
[self addChildViewController:thirdVC];
[self.contentView addSubview:thirdVC.view];
self.currentVC = thirdVC;
}
- (IBAction)onClick:(id)sender {
if (self.currentVC==firstVC && [sender tag]==100001) {
return;
}
if (self.currentVC ==secondVC && [sender tag] ==100002) {
return;
}
if (self.currentVC == thirdVC && [sender tag]==100003) {
return;
}
UIViewController * oldVC = self.currentVC;
switch ([sender tag]) {
case 100001:{
[self transitionFromViewController:self.currentVC toViewController:firstVC duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
} completion:^(BOOL finished) {
if (finished) {
self.currentVC = firstVC;
}else{
self.currentVC = oldVC;
}
}];
}
break;
case 100002:{
[self transitionFromViewController:self.currentVC toViewController:secondVC duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
} completion:^(BOOL finished) {
if (finished) {
self.currentVC = secondVC;
}else{
self.currentVC = oldVC;
}
}];
}
break;
case 100003:{
[self transitionFromViewController:self.currentVC toViewController:thirdVC duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
} completion:^(BOOL finished) {
if (finished) {
self.currentVC = thirdVC;
}else{
self.currentVC = oldVC;
}
}];
}
break;
default:
break;
}
}
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController:
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addChildViewController
- addchildviewcontroller
- addChildViewController方法
- ios addChildViewController
- addChildViewController用法
- C++归并排序代码
- 【bzoj1398】Vijos1382寻找主人 Necklace
- xshell连接linux中文编码问题
- Android传感器(一):传感器列表
- android listview系列之初步接触listview(一)
- addChildViewController
- Android三种实现自定义ProgressBar的方式介绍
- 学习笔记︱深度学习以及R中并行算法的应用(GPU)
- Mybatis 分表插件shardbatis2.0使用
- Java Redis初学之Hello World
- 2007提高。。。。。统计数组。。坑
- Android开发学习之路--Annotation注解简化view控件之初体验
- LeetCode题解-92-Reverse Linked List II
- Android-LinearGradient实现TextView字体渐变的效果