Responding to Display-Related Notifications

响应跟显示相关的通知

When the visibility of a view controller’s view changes, the view controller calls some built-in methods to notify subclasses of the changes. You can override these methods to override how your subclass reacts to the change. For example, you can use these notifications to change the color and orientation of the status bar so that it matches the presentation style of the view that is about to be displayed.

当一个视图控制器的视图可见性发生改变时,视图控制器调用一些内建的方法来通知子类发生的改变。 你可以重写(override)这些方法来实现(override)你的子类如何对改变做出反应。 比如,你可以使用这些通知来改变状态栏的颜色和方向,使其跟即将显示的视图风格相配套。

Responding When a View Appears

一、当视图显示时做出响应

Figure 5-1 shows the sequence of events that occurs when a view controller’s view is added to a window’s view hierarchy. The viewWillAppear: andviewDidAppear: methods give subclasses a chance to perform any additional actions related to the appearance of the view.

图5-1 显示了当一个视图控制器中的视图被添加到一个窗口视图层次里发生的一些列事件。 viewWillAppear: 方法 和 viewDidAppear: 方法让子类执行跟视图显示(appearance)相关的任何附加操作。

Figure 5-1  Responding to the appearance of a view

图 5-1 对一个视图的显示(appearance)做出响应

Responding When a View Disappears

二、当视图消失时做出响应

Figure 5-2 shows the sequence of events that occurs when a view is removed from its window. When the view controller detects that its view is about to be removed or hidden, it calls the viewWillDisappear: and viewDidDisappear: methods to give subclasses a chance to perform any relevant tasks.

图5-2 显示了当一个视图从窗口移除时所发生的一系列事件。 当视图控制器检测到其视图即将被删除或隐藏时,它调用  viewWillDisappear: 和 viewDidDisappear: 方法来让子类执行任何相关任务。

Figure 5-2  Responding to the disappearance of a view

图 5-2 响应一个视图的消失

Determining Why a View’s Appearance Changed

三、确定一个视图的显示状态改变的原因

Occasionally, it can be useful to know why a view is appearing or disappearing. For example, you might want to know whether a view appeared because it was just added to a container or whether it appeared because some other content that obscured it was removed. This particular example often appears when using navigation controllers; your content controller’s view may appear because the view controller was just pushed onto the navigation stack or it might appear because controllers previously above it were popped from the stack.

有时候,知道一个视图出现或消失的原因很有用。 比如,你可能因为一个视图e刚刚被添加到一个容而器想要知道它是否被显示,或者因为遮盖(obscured)这个视图的一些内容被移除了而想知道该视图是否被显示。 该特殊例子经常在使用导航控制器时出现;你的内容控制器中的视图可能在视图控制器刚被压入导航栈时出现,或者它可能因为前一个控制器被弹出栈而出现。

The UIViewController class provides methods your view controller can call to determine why the appearance change occurred. Table 5-1 describes the methods and their usage. These methods can be called from inside your implementation of the viewWillAppear:viewDidAppear:viewWillDisappear: andviewDidDisappear: methods.

UIViewController 类提供了一些方法可以让视图控制器调用来确定显示状态(appearance)发生改变的原因。 表格5-1 描述了这些方法以及它们的用途。 这些方法能从viewWillAppear: 和 viewDidAppear: 方法内部调用。

Table 5-1  Methods to call to determine why a view’s appearance changed

Method Name

Usage

isMovingFromParentViewController

You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was removed from its container view controller.

你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法,来确认视图控制器的视图是否正被隐藏,原因是视图控制器被从其容器视图控制器中删除。

isMovingToParentViewController

You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just added to a container view controller.

你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法,来确定视图控制器的视图是否正被显示,因为视图控制器刚刚被加入到一个容器视图控制器。

isBeingPresented

You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just presented by another view controller.

你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法来确定视图控制器中的视图是否正被显示,因为视图控制器正被另一个视图控制器呈现(present).

isBeingDismissed

You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was just dismissed.

你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法来确定视图控制器的视图是否正被隐藏,因为视图控制器刚刚被释放(dismissed)

View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications的更多相关文章

  1. View Controller Programming Guide for iOS---(二)---View Controller Basics

    View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ...

  2. View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views

    Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...

  3. View Controller Programming Guide for iOS---(一)---About View Controllers

    About View Controllers View controllers are a vital link between an app’s data and its visual appear ...

  4. View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers

    Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...

  5. View Controller Programming Guide for iOS---(三)---Using View Controllers in Your App

    Using View Controllers in Your App Whether you are working with view controllers provided by iOS, or ...

  6. View Controller Programming Guide for iOS---(五)---Resource Management in View Controllers

    Resource Management in View Controllers View controllers are an essential part of managing your app’ ...

  7. View Controller Programming Guide for iOS---(八)---Using View Controllers in the Responder Chain

    Using View Controllers in the Responder Chain 响应链中使用视图控制器 View controllers are descendants of the UI ...

  8. View Controller Programming Guid for iOS 笔记

    1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...

  9. View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views

    Views Because view objects are the main way your application interacts with the user, they have many ...

随机推荐

  1. UNIDAC不能识别CLIENTDATASET的TSINGLEFIELD

    UNIDAC不能识别CLIENTDATASET的TSINGLEFIELD FIREDAC,UNIDAC这些通用的数据引擎,对某种数据库的支持,细节方面总有BUG. UNIDAC6.2.8发现不能识别C ...

  2. Hive 外部表 分区表

      之前主要研究oracle与mysql,认为hive事实上就是一种数据仓库的框架,也没有太多另类,所以主要精力都在研究hadoop.hbase,sqoop,mahout,近期略微用心看了下hive. ...

  3. java开始到熟悉61

    本此主题:多维数组----矩阵运算 矩阵的运算规则是将对应位置的值进行运算,如上图所示. package array; public class Matrix { /** * 打印矩阵 * @para ...

  4. nginx+play framework +mongoDB+redis +mysql+LBS实战总结

    nginx+play framework +mongoDB+redis +mysql+LBS实战总结(一) 使用这个样的组合结构已经很久了,主要是实现web-server,不是做网站,二是纯粹的数据服 ...

  5. 互斥锁和条件变量(pthread)相关函数

    互斥锁 #include <pthread.h> // 若成功返回0,出错返回正的Exxx值 // mptr通常被初始化为PTHREAD_MUTEX_INITIALIZER int pth ...

  6. (转)gcc学习笔记

    1.gcc -Wall hello.c -o hello //编译源文件,显示警告信息 2../a.out   //运行程序 3.gcc -Wall calc.c /usr/lib/libm.a -o ...

  7. Storm项目:流数据监控1《设计文档…

    博客公告: (1)本博客全部博客文章搬迁至<博客虫>http://blogchong.com/ (2)文章相应的源代码下载链接參考博客虫站点首页的"代码GIT". (3 ...

  8. python的对象的属性(即对象的成员)是动态的

    1 python的对象的成员叫attribute 2 python的类的成员是可以动态创建的 因此,在用的时候也提供了三个内建的接口来对类的成员进行操作 2.1 getattr() 2.2 hasat ...

  9. hive impala C++ Java垃圾回收 Garbage Collection GC

    hive impala impala  推荐每个节点内存  2^7~2^8GB Impala与Hive的比较 - 文章 - 伯乐在线 http://blog.jobbole.com/43233/ &l ...

  10. JSON和JavaScript对象

    var obj={width:100,height:200},这样的并不叫JSON,并且JSON只是一种数据格式,并不是具体的实例. 但很多人把这样的JS对象当成JSON,下面把这个问题讲清楚 一.J ...