Storyboard简述
storyBoard(故事板)是苹果在iOS5中引入的新技术,是苹果一直推荐使用的界面开发方式。在近几年的 Xcode 更新中可以看出,苹果对 Storyboard 的开发力度也不断增强,添加了更多功能和特性,大大方便了界面的开发、适配以及提升代码性能。
简单的讲,StoryBoard可以看做是一组viewController对应的xib,以及它们之间的转换方式的集合.在StoryBoard中不仅可以看到每个ViewController的布局样式,也可以明确地知道各个ViewController之间的转换关系,这样条理更清晰。
本篇文章主要讲Storyboard Reference的使用,实现在一个工程中使用多个Storyboard开发的功能
进入开发
先看要达到的效果,有目标才有思路

从图中可以看出,我们将要实现的是一个有TabBar的工程,tabBar有5个item。那么下面开干。
一 、创建项目,用一个StoryBoard管理所有页面
1.创建一个新项目,给Main.Storyboard中的ViewController添加NavigationController。如下图

得到效果如下

2.给NavigationController添加TableBar。如下图

添加后的效果如下

这样就创建完成了一个完整的item,但是我们要创建5个item。
3.选中StoryBoard中的Navigation Controller 和View Controller,复制,然后粘贴4次。然后将复制出来的4个item的位置摆好(有时候会发现,你复制的4个item看不到,那是因为都重叠在第一个上面了,拖开就可以了)。如下图

4.从TabBar Controller往Navigation Controller上拖线,在弹出来的选择框中选view controllers。如下图

5.全部拖线完成以后,我门将各个ViewController的背景色改一下。如下图

为了效果好一点,我们给每个Navigation Controller的item放上图片。如下图

完事后,一个StoryBoard管理所有界面的项目完成,运行一下。结果如下图

二 、将项目分解为成一个总的StoryBoard,5个分的StoryBoard
这一步很简单,主要是用到 Storyboard Reference这个东西。
1.同时选择第一个item的 Navigation Controller和View Controller,然后在 editor的下拉列表中选择Refactor to Storyboard。如下图

然后会弹出保存方式的弹框

设置好文件名字,选择好保存位置,点击保存即可。保存完后会生成一个新的StoryBoard文件。如下图

原来的Main.StoryBoard也会变化。如下图

2.接下来将剩下的4个item也设置成Refactor to Storyboard。完成以后效果如下图所示

运行完成后,结果和一个StoryBoard管理所有控制器是一样的效果。
后记
到此多StoryBoard管理项目的创建方法介绍完毕。这样就不会存在一个StoryBoard中有大量的控制器,瞬间感觉乱麻被快刀斩。每一个模块管理一部分功能,而且子模块还可以分成子模块,听起来就感觉很刺激。
网友评论