Storyboards Tutorial 01
Storyboarding 是在ios 5时候引进入的一个非常出色的特性。节省了为app创建user interfaces的时间。
如果你的app有多个屏幕storyboards可以帮助你降低代码的粘合度。比如从一个屏幕进入到另外一个屏幕。不会为每一个view controller使用单独的nib文件。你的app将只使用一个storyboard就可以包含所有这些view controllers的设计和关系。
storyboard有很多优势:
可以对所有app中的屏幕以及他们之间的关系有个更好的概念上的概览。更容易跟踪一切因为整个设计是在单独的一个文件中。而不是分成多个独立的nib文件。
storyboard描述了不同屏幕间的传输。这些传输称为segues并且只要通过简单的ctrl-dragging从一个view controller到另一个就可以建立了。由于segues的存在减少了代码量
storyboard使得table view的设计和使用更加方便。包含了cels和static sells features和属性。
还可以讲storyboard和nib文件混用
Storyboards tutorial: iOS 7 style
打开xcode创建新的工程,使用single view applicaiton模版。
并填写如下的选项
- Product Name: Ratings
- Organization Name: fill this in however you like
- Company Identifier: the identifier that you use for your apps, in reverse domain notation
- Class Prefix: leave this empty
- Devices: iPhone
之前版本的xcode需要特别指出是否使用storyboards,但是xcode5不再有这个选项,storyboards默认可用。
创建完成后是下面这个样子:
新的工程有两个class,AppDelegate和ViewController. Main.storyboard文件,并且没有nib文件
这是一个只支持竖屏显示的app,所以需要在Deployment Info, Device Orientation 下面 uncheck Landscape Left和Landscape Right选项
打开Main.storyboard文件,在iphone中每次只有一个scene是可视的,但是在ipad中可以一次展示多个,例如master和detail panes或者popover content
Note: Xcode 5 enables Auto Layout by default for storyboard and nib files. Auto Layout is a cool new technology for making flexible user interfaces that can easily resize, which is useful on the iPad and for supporting the larger iPhone 5, but it only works on iOS 6 and up. It also has a bit of a learning curve, which is why you’re not using it in this tutorial. To learn more about Auto Layout, see our books iOS 6 by Tutorials and iOS 7 by Tutorials.
Dock显示了在这个scene中的top-level objects.每一个scene至少有一个view controller object,一个First Responder object和一个Exit item. 但是可以暗含其他的top-level objects. Dock方便使用connections to outlets和actions.如果你需要连接什么到view controller,你可以尝试简单drag他在dock中的图标。
Note: You probably won’t be using the First Responder very much. This is a proxy object that refers to whatever object has first responder status at any given time. It was also present in your nibs and you probably never had a need to use it then either. As an example, you can hook up the Touch Up Inside event from a button to First Responder’s cut: selector. If at some point a text field has input focus then you can press that button to make the text field, which is now the first responder, cut its text to the pasteboard.
如果你之前使用过nib app那么总是会有一个MainWindow.xib的文件。这个nib文件包含了top-level UIWindow object.一个app delegate的引用和一个或者多个view controllers。当你使用storyboard含纳你的app ui时,MainWindow.xib不再使用。那么storyboard又是如何被app加载的呢?
应用程序代理,打开AppDelegate.h可以看到:
这是个使用storyboards的要求,你的应用程序delegate需要继承自UIResponder并且有一个UIWindow的属性。如果查看AppDelegate.m,你会看到什么都没有。秘密在Ratings-Info.plist 文件中。
storyboards app使用关键字UIMainStoryboardFile或者Main storyboard file base name来指定当app启动时必须加载的storyboard名字。
当这个设置后,UIApplication在加载这个storyboard文件的时候会自动初始化这个storyboard中的第一个view controller,然后把它的views放到一个新的UIWindow object中去。这些都不需要自己写代码。在Project Settings窗口中的Deployment Info中也可以看到这个。
在main.m文件中,
app delegate不是storyboard的一部分。你必须传递app delegate class的名字到UIApplicationMain(),否则无法找到它。
Just Add It To My Tab
这个Rating app有一个tabbed interface包含两个屏幕。利用storyboard非常容易创建这个tabs。
打开Main.storyboard,并且拖放一个Tab Bar Controller有两个view controllers附带。
两个view controllers每个对应一个tab。UITabBarController之所以称为container view controller是因为它包含一个或者多个view controllers.
container 关系被Tab Bar Controller和view controllers之间的arrows代表着。
Note: If you want to move the Tab Bar Controller and its attached view controllers as a group, you can ⌘-click to select multiple scenes and then move them around together. (Selected scenes have a thick blue outline.)
drag一个label到第一个view controller中并且设置文本为"First Tab".并且拖一个label到第二个view controller中去并命名为"Second Tab".
选择tab bar controller并且进到Attributes inspector中勾选box "Is Initial View Controller".
这时候会发现之前指向regular view controller的箭头指向了tab bar controller
这表明当你启动app的时候,UIApplication会讲tab bar controller包含进main screen. storyboard总是有一个单独的view controller被设计成initial view controller,即storyboard的入口点
Tip: To change the initial view controller, you can also drag the arrow between view controllers. 也可以拖拉箭头来指定initial view controller
运行app后的效果:
Note: If you connect more than five scenes to the Tab Bar Controller, it automatically gets a More… tab when you run the app. Pretty neat!
如果你连接了超过5个屏幕到tab bar controller,它会自动得到一个more的tab,非常灵巧
Storyboards Tutorial 01的更多相关文章
- Tutorial 01 4,5题
.任务四: 程序设计思想:利用Math.random()产生一个char类型的字符,再利用for循环是他们相加,最后将他们放在一个消息框中输出. 程序流程图: 源程序: p ...
- Vulkan Tutorial 01 开发环境搭建之Windows
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 相信很多人在开始学习Vulkan开发的起始阶段都会在开发环境的配置上下一些功夫,那么 ...
- Storyboards Tutorial 04
设计好后运行发现没有任何变化,是空白的.这是因为你的tableview相关的delegate方法还在.所以首先要屏蔽或者删除在PlayerDetailsViewController.m 如下的操作 # ...
- Storyboards Tutorial 03
这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...
- Storyboards Tutorial 02
内容中包含 base64string 图片造成字符过多,拒绝显示
- OpenGL 学习笔记 01 环境配置
以下教程仅适用于Mac下的Xcode编程环境!其他的我也不会搞. 推荐教程:opengl-tutorial 本项目Github网址 OpenGL太可怕了...必需得把学的记下来,不然绝壁 ...
- sqlzoo - SELECT from WORLD Tutorial 答案
01.SELECT from WORLD Tutorial 01.显示所有国家的名称,大洲和人口. SELECT name, continent, population FROM world; 02. ...
- IOS 开发教程
http://www.raywenderlich.com/category/ios http://www.raywenderlich.com/50310/storyboards-tutorial-in ...
- 30 分钟开发一个简单的 watchOS 2 app <oneVcat>
Apple Watch 和 watchOS 第一代产品只允许用户在 iPhone 设备上进行计算,然后将结果传输到手表上进行显示.在这个框架下,手表充当的功能在很大程度上只是手机的另一块小一些的显示器 ...
随机推荐
- windows phone UI吐槽---跑偏了就再也跑不回来了
首先wp的ui灵感来自瑞士的平面设计: 先上两张图,嗯,确实不错,简洁明了,强调的是信息本身,而不是冗余的界面元素,传达准确. 在现实生活中这种突出信息的设计语言也不时见到: 可以总结 ...
- ios开发第一步--虚拟机安装MAC OS X
暂时还没买Macbook,先用虚拟机练练手. 先说说准备工作,我是在win8下安装的,这个不是关键的,只要Vmware版本和MAC OS X版本确定就行了,win7下同样可以. 1.虚拟机Vmware ...
- 后缀数组(SA)学习记录
一只只会后缀自动机却不会后缀数组的弱鸡做了一下HDU - 1403,结果SAM被卡内存了,然后学习了一下SA. 以下两道题都是求LCS,区别在于字符串长度. 参考blog:https://www.cn ...
- 零基础学习 Python 之字符串
初识字符串 维基百科对于字符串的定义式:字符串是由零个或者多个字符组成的有限串行.你之前学会敲的第一行 print 代码里的 "Hello World",就是一个字符串.字符串的本 ...
- gcc学习记录
-Wall: 使输出中包含警告信息,提示一些可以避免的错误.如果没有错误,则不会输出信息. -o:后面加上可执行文件的名字.如果不加-o选项,会默认生成a.out可执行文件.举例:gcc -Wall ...
- python 模块初识
python的强大之处在于有丰富的实现各种功能的标准库和第三方库,另外还允许用户自己建立库文件, 标准模块(又称为库)包括sys, os, glob, socket, threading, _thre ...
- 环境说明与HelloWorld
本人采用的是ExtJs4.2版本,采用WebStorm作为IDE开发工具 目录说明 builds:压缩后的ExtJs代码 docs:文档 examples:官方示例 locale:多国语言的资源文件 ...
- HTML+CSS 滚动条样式自定义 - 适用于 div,iframe, html 等
友言:这两天被滚动条整的无与伦比,在此做下总结: 首先自定义浏览器滚动条的实现原理:计算浏览器滚动条的高度,层级1的高度与滚动条的总高度是一样的,通过相似比例计算: 浏览器滚动条总高度 :滚动条高度 ...
- webpack+babel+ES6+react环境搭建
webpack+babel+ES6+react环境搭建 步骤: 1 创建项目结构 注意: 先创建一个项目目录 react 这个名字自定义,然后进入到这个目录下面 mkdir app //创建app ...
- POJ3687 Labeling Balls
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13645 Accepted: 3955 Description Wind ...