RootViewController.m代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
//添加切换视图按钮
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(50, 100, 100, 50)];
[btn setTitle:@"切换视图" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(didBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)didBtn:(UIButton *)sender{
OtherViewController *other=[[OtherViewController alloc]init];
other.name=@"张三";//属性传值
//[other setModalTransitionStyle:UIModalTransitionStyleCoverVertical];//默认从下面拉入
//[other setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];//溶解
//[other setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];//水平翻转
[other setModalTransitionStyle:UIModalTransitionStylePartialCurl];//翻页
//切换视图
[self presentViewController:other animated:YES completion:nil];
}
OtherViewController.m代码:
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(50, 100, 100, 50)];
[btn setTitle:@"关闭视图" forState:UIControlStateNormal];
btn.backgroundColor=[UIColor blueColor];
[btn addTarget:self action:@selector(closeBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
NSLog(@"name=%@",self.name); //属性值
}
-(void)closeBtn:(UIButton *)sender{
//关闭视图
[self dismissViewControllerAnimated:YES completion:nil];
}