创建两个viewController类,使它们继承于UIViewController
RootViewController.m
- (void)viewDidLoad {
1.创建"下一页"按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"下一页" forState:UIControlStateNormal];
button.frame = CGRectMake(100, 100, 100, 50);
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
2.实现click方法,并在其中实现模态跳转.
- (void)click:(UIButton *)button {
3.创建SecondViewController对象.
SecondViewController *secondVC = [[SecondViewController alloc] init];
4.设置模态跳转的动画效果.
[secondVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
5.实现模态跳转.
[self presentViewController:secondVC animated:YES completion:^{
}];
6.内存释放.
[secondVC release];
}
SecondViewController.m
- (void)viewDidLoad {
7.创建"返回”按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"返回" forState:UIControlStateNormal];
button.frame = CGRectMake(100, 100, 100, 50);
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
8.实现click方法,并在其中实现返回.
- (void)click:(UIButton *)button {
9.返回上一页
[self dismissViewControllerAnimated:YES completion:^{
}];
}