码迷,mamicode.com
首页 > 其他好文 > 详细

storyBoard

时间:2016-03-04 22:40:48      阅读:442      评论:0      收藏:0      [点我收藏+]

标签:

1.没有连线的页面跳转

 1 #import "ViewController.h"
 2 #import "FirstViewController.h"
 3 @interface ViewController ()
 4 
 5 @end
 6 
 7 @implementation ViewController
 8 
 9 - (void)viewDidLoad {
10     [super viewDidLoad];
11     // Do any additional setup after loading the view, typically from a nib.
12 }
13 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
14 {
15     //如果在Main.storyBoard中两个Controller没有连线的情况下,应该根据相应的Controller去storyBoard中去找
16     FirstViewController *firstVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstViewController"];
17     [self.navigationController pushViewController:firstVC animated:YES];
18     /*
19      如果是自定义的storyBoard应该按照如下方式进行跳转
20      1.先找到这个storyBoard
21        参数1:写成自定义storyBoard的名字,参数2:访问文件
22      UIStoryboard *cunstomStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
23      2.然后再取相应的controller
24      FirstViewController *firstVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstViewController"];
25      [self.navigationController pushViewController:firstVC animated:YES];
26      */
27     
28     //
29 }
30 - (void)didReceiveMemoryWarning {
31     [super didReceiveMemoryWarning];
32     // Dispose of any resources that can be recreated.
33 }
34 
35 @end

2.storyBoard中view的页面传值和跳转

 1 #import "ViewController.h"
 2 #import "ThirdViewController.h"
 3 #import "SecondViewController.h"
 4 @interface ViewController ()
 5 @property (weak, nonatomic) IBOutlet UITextField *textField;
 6 
 7 @end
 8 
 9 @implementation ViewController
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     // Do any additional setup after loading the view, typically from a nib.
14     /*
15      使用自定义segue进行segue进行页面跳转传值步骤
16      1.先在storyBoard中拖两个Controller界面,然后使用custom方式进行两个界面的连线
17      2.在左侧自定义segue继承与UIStoryBoardSegue(重写preform,在此方法中找到source 和destination 两个Controller,然后添加UIView翻转动画,此时应该注意:这一步只完成了View的一个效果的翻转,真正的controller还没有进入,所以需要在block动画完成的时候写一个push效果或者present效果)
18      3.将自定义的Segue和storyBoard中的Segue线进行关联
19      4.添加相关的插座变量还有接受数值的属性定义在destination的外部
20      5.在原source 的prepareForSegue方法里边写跳转的逻辑,如果一个界面有多个segue,此时需要给segue设置标识,以便判断相关的判断,然后实现需求
21      */
22 }
23 
24 - (void)didReceiveMemoryWarning {
25     [super didReceiveMemoryWarning];
26     // Dispose of any resources that can be recreated.
27 }
28 
29 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
30 {
31     /**
32      *  找到目的Controller
33      */
34     ThirdViewController *thirdVC = (ThirdViewController *)segue.destinationViewController;
35     //一个界面的segue较多的时候需要给segue加标识然后根据标识去判断实现相关的效果
36     if ([segue.identifier isEqualToString:@"CustomSegue"]) {
37         //传值
38         thirdVC.content = self.textField.text;
39     }
40     SecondViewController *secondVC = (SecondViewController *)segue.destinationViewController;
41     if ([segue.identifier isEqualToString:@"SecondModal"]) {
42         secondVC.content = self.textField.text;
43         
44     }
45 
46 }
47 
48 @end
 1 #import "CustomSegue.h"
 2 #import "ViewController.h"
 3 #import "ThirdViewController.h"
 4 @implementation CustomSegue
 5 //重写自定义segue的方法
 6 -(void)perform
 7 {
 8     //获取要跳转的controller
 9     ViewController *sourceVC = (ViewController *)self.sourceViewController;
10     //获取目的Controller
11     ThirdViewController *destination = (ThirdViewController *)self.destinationViewController;
12     
13     [UIView transitionFromView:sourceVC.view toView:destination.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
14         //动画完成之后要进行的内容
15 #warning  重要
16         [sourceVC.navigationController pushViewController:destination animated:NO];
17         
18     }];
19 
20    
21 }
22 @end

技术分享

必须保证标识的一致性,此外Segue关联的类以及类型也必须相匹配

storyBoard

标签:

原文地址:http://www.cnblogs.com/DevinSMR/p/5243497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!