假设A跳转到B,三种方法:
1.按住ctrl键,拖动A上的控件(比如说UIButton)到B上,弹出菜单,选择Modal.不需要写任何代码,在A上点击Button就会跳转到B
2. 按住ctrl键,拖动A上的View Controller到B上,弹出菜单,选择Modal,两个场景间自动添加连接线和图标,选中该图标,打开Storyboard Segue,identifier输入一个标识符,这里以”aaaa”为例.A里需要跳转时,执行下面的代码:
1 |
[self performSegueWithIdentifier:@"aaaa" sender:self]; |
3.完全用代码来实现,代码如下:
1 2 3 4 5 6 7 8 9 |
//先获取UIStoryBoard对象,参数为文件名 UIStoryboard *mainStoryBoard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; //获取SecondViewController实例,参数是StoryBoard ID,选中View Controller,在Identity Inspector中 SecondViewController *second=[mainStoryBoard instantiateViewControllerWithIdentifier:@"second"]; //设置过渡的样式,和显示的样式 second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; second.modalPresentationStyle=UIModalPresentationFormSheet; //显示 [self presentViewController:second animated:YES completion:nil]; |