//UIViewController 模式跳转
ViewController *mvc = [[ViewController alloc]init];
[self.viewController presentViewController:mvc animated:YES completion:^{
}];
[mvc release];
//关闭模式对话框窗体,跳转回去。
[self.viewController dismissViewControllerAnimated:YES completion:^{
}];
//设置跳转方式
mvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
#import "ViewController.h"
#import "SubViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadView
{
[super loadView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 30, 80, 40);
[button setTitle:@"open modal" forState:UIControlStateNormal];
[button addTarget:self action:@selector(openModel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.view.backgroundColor = [UIColor greenColor];
}
- (void)openModel
{
//模式对话框跳转
SubViewController *sub = [[SubViewController alloc]init];
//设置跳转效果
// sub.modalTransitionStyle = UIModalTransitionStyleCoverVertical;//上下
// sub.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //左右反转
// sub.modalTransitionStyle = UIModalTransitionStylePartialCurl; //翻页
sub.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //直接跳转
[self presentViewController:sub animated:YES completion:^{}];
[sub release];
}
@end
#import "SubViewController.h"
@interface SubViewController ()
@end
@implementation SubViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadView
{
[super loadView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 30, 80, 40);
[button setTitle:@"close modal" forState:UIControlStateNormal];
[button addTarget:self action:@selector(closeModel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.view.backgroundColor = [UIColor redColor];
}
- (void)closeModel
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
@end
ios UIViewController
最新推荐文章于 2016-10-12 18:45:31 发布