View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications
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: 方法内部调用。
Method Name |
Usage |
---|---|
You call this method inside your 你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法,来确认视图控制器的视图是否正被隐藏,原因是视图控制器被从其容器视图控制器中删除。 |
|
You call this method inside your 你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法,来确定视图控制器的视图是否正被显示,因为视图控制器刚刚被加入到一个容器视图控制器。 |
|
You call this method inside your 你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法来确定视图控制器中的视图是否正被显示,因为视图控制器正被另一个视图控制器呈现(present). |
|
You call this method inside your 你可以在viewWillAppear: 和 viewDidAppear: 方法内部调用该方法来确定视图控制器的视图是否正被隐藏,因为视图控制器刚刚被释放(dismissed) |
View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...
- 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 ...
- 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’ ...
- 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 ...
- View Controller Programming Guid for iOS 笔记
1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...
- View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views
Views Because view objects are the main way your application interacts with the user, they have many ...
随机推荐
- 统计显著性(Statistical significance)
显著性,又称统计显著性(Statistical significance), 是指零假设为真的情况下拒绝零假设所要承担的风险水平,又叫概率水平,或者显著水平. [1] 显著性的含义是指两个群体的态度之 ...
- php 解决MySQL插入数据出现 Incorrect string value: '\xF0\x9F\x92\x8BTi...'错误
在项目中向MySQL插入数据时.发现数据插入不完整,通过调试,发现插入语句也没什么特殊的错误. 可是就是差不进去,于是就打开mysqli错误的调试 $ret = mysqli_query($this- ...
- Ikki's Story IV - Panda's Trick (poj 3207 2-SAT)
Language: Default Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total S ...
- win10 UWP 申请微软开发人员
申请微软开发人员能够到https://dev.windows.com/zh-cn/programs/join 假设是学生,先去http://www.dreamspark.com/ 假设是英文,点stu ...
- 最小公倍数(Least Common Multiple)
最小公倍数=两个数的乘积/两个数的最大公约数. 接上篇求最大公约数方法,最小公倍数的代码例如以下: public class LCM { //最小公倍数=两数乘积/最大公约数 public stati ...
- 程序的载入和运行(五)——《x86汇编语言:从实模式到保护模式》读书笔记25
程序的载入和运行(五)--<x86汇编语言:从实模式到保护模式>读书笔记25 前面几篇博文最终把代码分析完了.这篇就来说说代码的编译.运行和调试. 1.代码的编译及写入镜像文件 之前我们都 ...
- 【算法编程】找出仅仅出现一次的数-singleNumber
题目意思: 一个数值数组中,大部分的数值出现两次,仅仅有一个数值仅仅出现过一次,求编程求出该数字. 要求,时间复杂度为线性,空间复杂度为O(1). 解题思路: 1.先排序.后查找. 因为排序的最快时间 ...
- 一个简单演示样例来演示用PHP訪问表单变量
首先编写表单页面orderform.html,用post方法请求服务端脚本文件:processorder.php orderform.html: <!DOCTYPE html> <h ...
- npm的安装和更新
https://nodejs.org官网下载软件安装 验证是否安装,进入命令行 输入npm -v 这个是安装node自动带的工具 npm install npm@xxx 自动更新自己,后边跟版本号 n ...
- java中InputStream String
Java 中获取输入流时,有时候须要将输入流转成String,以便获取当中的内容 ,以下总结一下 InputStream 转成String 的方式 方法1: public String conver ...