Heim  >  Artikel  >  Web-Frontend  >  StoryBoard初探(一):实现简单的页面跳转与返回_html/css_WEB-ITnose

StoryBoard初探(一):实现简单的页面跳转与返回_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:51:521282Durchsuche

前言

苹果推出故事版很久了,一直没有深入学习过。最近打算尝试用StoryBoard做高保真交互App原型,决定学习下。相对于IB来讲,StoryBoard几乎不用手写代码,便能实现页面交互,这一点很适合会Xcode的同学用来做快速原型开发。


实现简单的页面跳转

新建工程,选择Single View Application,Xcode生成的工程模板中会自动使用StoryBoard.打开Main.storyboard文件,可以像IB一样,拖拽视图对象到ViewController的View上。如图,简单的加一个页面标示UILabel标签和一个UIButton按钮:




向主窗口中拖拽一个UIViewController对象,作为第二个页面,按住Ctrl键,拖拽按钮连线新添加的页面




松开鼠标在弹出的黑色悬浮框列表中选择Action Segue的类型为:Modal,这样在点击橙色按钮之后,页面2将从页面1底部弹出




页面2返回页面1,在页面2上添加一个按钮,在ViewController.m文件中实现一个带UIStoryBoardSegue类型参数的IBAction方法


- (IBAction)unwindSegue:(UIStoryboardSegue *)sender{    NSLog(@"unwindSegue %@", sender);}

Ctrl连线页面2上的按钮到ViewController的Exit,并关联unwindSegue:方法






模拟器中的运行效果:



代码实现

页面1跳转页面2:先清除按钮连线,然后Ctrl连线ViewController到ViewController2,选择Modal类型



选中ViewController与ViewController2之间的连接,并设置连接的Identifier为:2vc2



在ViewController.m中添加代码,并关联按钮

- (IBAction)presentVC2:(id)sender {    NSLog(@"代码实现页面跳转");    [self performSegueWithIdentifier:@"2vc2" sender:sender];}

页面2返回页面1,先清除按钮连线,然后在ViewController2.m中添加IBAction方法并关联返回按钮:

- (IBAction)backAction:(id)sender {    [self dismissViewControllerAnimated:YES completion:nil];}



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn