Programming Guide for iOS---View Controller控制器

4视图Programming Guide for iOS---View

Use the storyboard editor to do the following:

* Add, arrange, and configure the views for a view controller.

* Connect outlets and actions; see Handling User Interactions.

* Create relationships and segues between your view controllers; see Using Segues.

* Customize your layout and views for different size classes; see Building an Adaptive Interface.

* Add gesture recognizers to handle user interactions with views; see Event Handling Guide for iOS.



1控制器 Programming Guide for iOS---View Controller

主题:View Management—data marshaling——user interactions———resource management——adaptivity

UIAccessibilityScreenChangedNotificationSupporting Accessibility  支持可访问

手势Escape退出

Content view controllers:离散的内容片

Container view controllers :从其他的view controllers(child view controllers) 收集信息并呈现,

容器控制器:does not manage the content of its children. It manages only the root view, sizing and placing it according to the container’s design.

to combine the content from multiple view controllers into a single user interface.

视图控制器之间的关系定义了每个视图所需要的行为

The root view controller is the anchor of the view controller hierarchy.

window 的属性

管理视图层to manage a hierarchy of views

每个视图控制器 都是一个独立的岛屿    Make Each View Controller an Island

两个视图控制器之间通过协议交流

The exact type of the delegate object is unimportant. All that matters is that it implements the methods of the protocol

A UIDocument object is one way to manage your data separately from your view controllers.

The view controller might store a copy of any data it receives to make it easier to update views, but the document still owns the true data.

UIViewController与UIDocument的关系:no default relationship exists between the two

the view controller should only cache information from the document for efficiency. The actual data still belongs to the document object.

UIDocument抽象基础类

1、在后台异步读写数据

2、自动在合适的时候保存数据,并替换当前文件

处理用户交互:::::view controllers rarely handle touch events directly

1、 Action methods

2、notifications

3、View controllers act as a data source or delegate for another object

remove references to objects that you no longer need or can recreate easily later

remove references to objects删除的对象的引用

need to handle coarse-grained changes and fine-grained changes需要处理粗粒度和细粒度的变化

粗粒度变化:根据特征变化,特征包含在display scale、horizontal size 、vertical size.

rotates an iPhone from portrait to landscape

the size class might not change but the screen dimensions usually change.

View controllers can make additional adjustments as needed.

----updates the layout information,并让其他相关的控制器 know abut the layout changes

the layout process

Updates the trait collections of the view controller and its views, as needed; see When Do Trait and Size Changes Happen?

Calls the view controller’s viewWillLayoutSubviews method.

Calls the containerViewWillLayoutSubviews method of the current UIPresentationController object.

Calls the layoutSubviews method of view controller’s root view.

The default implementation of this method computes the new layout information using the available constraints. The method then traverses the view hierarchy and calls layoutSubviews for each subview.

Applies the computed layout information to the views.

Calls the view controller’s viewDidLayoutSubviews method.

Calls the containerViewDidLayoutSubviews method of the current UIPresentationController object.

Here are some tips for managing your layout effectively:

* Use Auto Layout. The constraints you create using Auto Layout are a flexible and easy way to position your content on different screen sizes.

* Take advantage of the top and bottom layout guides. Laying out content to these guides ensures that your content is always visible. The position of the top layout guide factors in the height of the status bar and navigation bar. Similarly, the position of the bottom layout guide factors in the height of a tab bar or toolbar.

* Remember to update constraints when adding or removing views. If you add or remove views dynamically, remember to update the corresponding constraints.

* Remove constraints temporarily while animating your view controller’s views. When animating views using UIKit Core Animation, remove your constraints for the duration of the animations and add them back when the animations finish. Remember to update your constraints if the position or size of your views changed during the animation.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,437评论 0 23
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 597评论 0 0
  • 常听到有人抱怨世态炎凉,人心冷漠,但其实,这个世界并没有你想象得那么糟。 人生,总有一些不期而遇的...
    memory89阅读 181评论 0 0
  • 周五度过了今年以来最忙的一天。 刚上班接到学校群通知,下周交毕业论文的题纲。 下午国家基金专家开会。 工作、学习的...
    蕊蕊啊阅读 217评论 0 1
  • 那年,我们喜欢一起沿着跑道绕着圈。任凭热浪打在脸上.吹在心里.一圈圈不知疲惫的走着.好似一直不停歇的走就会把...
    九锥加三阅读 366评论 0 0