Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom

1、视图切换类型介绍
在storyboard中,segue有几种不一样的类型,在iphone和ipad的开发中,segue的类型是不一样的。
在iphone中,segue有:push,modal,和custom三种不一样的类型,这些类型的区别在与新页面出现的方式。
而在ipad中,有push,modal,popover,replace和custom五种不一样的类型。

modal 模态转换

 
最经常使用的场景,新的场景彻底盖住了旧的那个。用户没法再与上一个场景交互,除非他们先关闭这个场景。
是在viewController中的标准切换的方式,包括淡出什么的,能够选切换动画。
Modalview:就是会弹出一个view,你只能在该view上操做,而不能切换到其余view,除非你关闭了modalview.
Modal View对应的segue type就是modal segue。
*Modal:Transition to another scene for the purposes of completing a task.当user在弹出的modalview里操做完后,就应该dismiss the modal view scene而后切换回the originalview.

push


Push类型通常是须要头一个界面是个Navigation Controller的。
是在navigation View Controller中下一级时使用的那种从右侧划入的方式
*Push:Create a chain of scenes where the user can move forward or back.该segue type是和navigation viewcontrollers一块儿使用。

popover(iPad only)

 
popover 类型,就是采用浮动窗的形式把新页面展现出来
*Popover(iPad only):Displays the scene in a pop-up “window” over top of the current view.
 
 

*Replace (iPad only):

 
替换当前scene,
Replace the current scene with another. This is used in some specialized iPad viewcontrollers (e.g. split-view controller).

custom


就是自定义跳转方式啦。
*Custom:Used for programming a customtransition between scenes.
在Storyboard中使用自定义的segue类型
参考资料:
使用StoryBoard:用Segue传递数据
http://www.cnblogs.com/mybkn/archive/2012/03/22/2411842.html 
WWDC2011视频之Introduction to Storyboarding摘要
http://blog.sina.com.cn/s/blog_834f346f0100s4jr.html
storyboard 遇到一个segue的问题
http://www.cocoachina.com/bbs/simple/?t92552.html
 
2、StoryBoard的视图切换

一 、简述html

Storyboard是你能够用来定义用户界面的一种新的方式,像xib。xcode

与xib不一样的是它能够同时管理多个ViewController,并且能够在Storyboard中配置ViewController 之间的跳转关系。app

 

2、Storyboard使用iphone

若是你是建立新项目,Xcode模版能够提供一个配置好的Storyboard供你使用。对于其它的应用,使用Storyboard的过程以下:ide

一、配置应用程序Info.plist文件动画

  • 添加UIMainStoryboardFile ,值为storyboard的文件名。
  • 删除原来的NSMainNibFile

二、像之前建立xib文件同样建立一个storyboard文件ui

三、配置 storyboard中的viewControllerspa

 

3、Storyboard的建立.net

            你能够用InterfaceBuilder 去为你的应用程序建立一个Stroyboard,通常来讲一个应用使用一个 Storyboard就够了,可是若是你想建立多个也是能够的,只要你愿意。一个 Stroyboard应该至少含有一个ViewController。code

            在iPhone中,对于每个在Storyboard的ViewController都管理着一个scene,每一个scene又管理着screen上的东东,但对于iPad来讲,多个scene能够同时呈如今一个screen上。你能够从library中拖拽viewController到你的Storyboard上。

            当你想关联两个viewController时,你能够按着control键,用鼠标从一个ViewController中的button,table view cell…拖拽链接到另外一个你想跳转到的ViewController,这样就建立了一个segue,不要忘记设置identifier哦。

           

4、 Scene之间的数据传递

            当你从当前 scene中触发一个segue的时候,系统会自动调用prepareForSegue:sender:这个方法。若是你想从一个界面切换到里另外一个界面的时候传递数据,你应该override这个方法。

 

A---》B

想把数据  NSString A_data   从AController传到BController,则在BController中  

@property 一个NSString data

而后在AController中添加方法

 

[objc]  view plain  copy
 
 在CODE上查看代码片派生到个人代码片
  1. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender  
  2. {  
  3.     NSLog(@"The segue id is %@", segue.identifier );  
  4.     UIViewController *destination = segue.destinationViewController;     
  5.     if ([destination respondsToSelector:@selector(setData:)])   
  6.     {  
  7.         [destination setValue:@"这是要传递的数据" forKey:@"data"];  
  8.     }      
  9. }  

 

以后,Bcontroller中的data属性,就接收到数据了。

 

5、ViewController之间的跳转

            一、若是在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则能够执行performSegueWithIdentifier:sender:这个方法实现跳转。

            二、若是目标ViewController存在Storyboard中,可是没有segue。你能够经过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,而后再用你想要的方式实现跳转,如:压栈。

            三、若是目标ViewController不存在,那就去建立它吧。

相关文章
相关标签/搜索