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 contents. In the process, the view controller also manages the view’s subviews. But in most cases, the view’s frame is not set directly by the view controller. Instead, the view’s frame is determined by how the view controller’s view is displayed. More directly, it is configured by the object used to display it. Other conditions in the app, such as the presence of the status bar, can also cause the frame to change. Because of this, your view controller should be prepared to adjust the contents of its view when the view’s frame changes.
视图控制器有自己的视图并管理视图的内容。 在过程中,视图控制器还管理视图的子视图。 但是在大多数情况下,视图的框架并不是由视图控制器直接设置。相反,视图的框架由视图控制器的视图如何显示决定。更直接地说,它由显示它的对象来配置。 应用程序中的其它情况,比如状态栏的出现也可以导致框架发生改变。 因此,当视图的框架变化时,你的视图控制器应该准备好调整它的内容。
A Window Sets the Frame of Its Root View Controller’s View
一、窗口设置其根视图控制器视图的框架
The view associated with the window’s root view controller gets a frame based on the characteristics of the window. The frame set by the window can change based on a number of factors:
跟窗口的根视图控制器相关的视图根据窗口的特性来获取框架。 由窗口设置的框架会基于以下因素发生改变:
The frame of the window
- 窗口的框架
Whether or not the status bar is visible
- 状态栏是否可见
Whether or not the status bar is showing additional transient information (such as when a phone call is in progress)
- 状态栏是否显示额外的临时信息(比如来电)
The orientation of the user interface (landscape or portrait)
- 用户界面的朝向(水平或是垂直)
The value stored in the root view controller’s
wantsFullScreenLayout
property- 根视图控制器的
wantsFullScreenLayout 特性值
If your app displays the status bar, the view shrinks so that it does not underlap the status bar. After all, if the status bar is opaque, there is no way to see or interact with the content lying underneath it. However, if your app displays a translucent status bar, you can set the value of your view controller’swantsFullScreenLayout
property to YES
to allow your view to be displayed full screen. The status bar is drawn over the top of the view.
如果你的应用程序显示状态栏,视图缩小以便它不与状态栏重叠(underlap)。 毕竟如果状态栏不透明,我们没有办法查看或跟状态栏下面的内容想交互。 然而,如果你的程序显示一个半透明状态栏,你可以把视图控制器的wantsFullScreenLayout 特性设置为YES来让视图全屏显示。 状态栏覆盖在视图的顶部。
Full screen is useful when you want to maximize the amount of space available for displaying your content. When displaying content under the status bar, place that content inside a scroll view so that the user can scroll it out from under the status bar. Being able to scroll your content is important because the user cannot interact with content that is positioned behind the status bar or any other translucent views (such as translucent navigation bars and toolbars). Navigation bars automatically add a scroll content inset to your scroll view (assuming it is the root view of your view controller) to account for the height of the navigation bar; otherwise, you must manually modify the contentInset
property of your scroll view.
当你想要最大空间来显示你的内容时全屏很有用。 当在状态栏下面显示内容时,把那些内容放入一个滚动视图,这样用户滚动出在状态栏下面的内容。 让你的内容可以滚动是很重要的,因为用户不能跟位于状态栏或任何其它半透明的视图(比如半透明的导航栏和工具栏)后面的内容想交互。 导航栏自动添加一个滚动内容嵌入(inset to)到你的滚动视图(假设它是你的视图控制器的根视图),用来占用(account)导航栏的高度。另外,你必须手动修改滚动视图的 contentInset特性。
A Container Sets the Frames of Its Children’s Views
二、容器设置其子女的视图框架
When a view controller is a child of a container view controller, its parent decides which children are visible. When it wants to show the view, it adds it as a subview in its own view hierarchy and sets its frame to fit it into its user interface. For example:
当一个视图控制器是一个容器视图控制器的子视图时,它的父视图决定哪些子视图可见。 当它想要显示视图时,它把它左右一个子视图添加到自己的视图层次结构并且设置它的框架让它适合用户界面。 比如:
A tab view controller reserves space at the bottom of its view for the tab bar. It sets the currently visible child’s view to use the remainder of the space.
- 标签视图控制器为标签栏保留了其视图底部空间。 它设置单前可见的子视图的视图来使用该剩余(remainder)空间。
A navigation view controller reserves space at the top for the navigation bar. If the currently visible child wants a navigation bar to be displayed, it also places a view at the bottom of the screen. The remainder of its view is given to the child to fill.
- 导航视图控制器为导航栏在顶部保留了空间。 如果当前可见的子视图想要显示一个导航栏,它还可以在屏幕的底部放置一个视图。 该视图的剩余空间可以让子视图来填充。
A child gets its frame from the parent all the way up to the root view controller, which gets its frame from the window.
一个子视图从其父视图那获取框架,一直延伸直到根视图控制器。根视图控制器的框架从窗口获取。
A Presented View Controller Uses a Presentation Context
三、一个被呈现的视图控制器使用一个陈述上下文
When a view controller is presented by another view controller, the frame it receives is based on the presentation context used to display the view controller. See“Presentation Contexts Provide the Area Covered by the Presented View Controller.”
当一个视图控制器由另一个视图控制器呈现时,它的框架基于用来显示视图控制器的陈述上下文(presentation context)。 查看“Presentation Contexts Provide the Area Covered by the Presented View Controller.”
A Popover Controller Sets the Size of the Displayed View
四、弹出控制器设置被显示视图的尺寸
A view controller displayed by a popover controller can determine the size of its view’s area by setting its own contentSizeForViewInPopover
property value to the size it wants. If the popover controller sets its own popoverContentSize
property to a different view size, its size value overrides the view controller’s setting. To match the model used by other view controllers, use the popover controller’s properties to control its size and position.
由弹出控制器显示的视图控制器可以决定其视图区的尺寸,它把自己的contentSizeForViewInPopover特性值设置为需要的值。 如果弹出控制器把自己的 popoverContentSize 特性设置为一个不同的视图尺寸,它的尺寸值重写视图控制器的设置。 要想匹配其它视图控制器使用的模型,使用弹出控制器的特性来控制它的尺寸和位置。
How View Controllers Participate in the View Layout Process
五、视图控制器如何参与视图布局进程
When the size of a view controller’s view changes, its subviews are repositioned to fit the new space available to them. The views in the controller’s view hierarchy perform most of this work themselves through the use of layout constraints and autoresizing masks. However, the view controller is also called at various points so that it can participate in the process. Here’s what happens:
当一个图控制器的尺寸改变时,它的子视图将被重新定位以适应为它们的新空间。 视图控制器的视图层次中的视图大多数由自己执行该工作,它们通过使用布局常量和自动尺寸调整蒙版(autoresizing masks). 然而,视图控制器也在不同点被调用,这样它就可以参与进程。以下是发生的事情:
The view controller’s view is resized to the new size.
视图控制器的尺寸被重新设置为新尺寸。
If autolayout is not in use, the views are resized according to their autoresizing masks.
如果没有使用自动布局,视图根据它们的自动调整尺寸蒙版来调整尺寸。
The view controller’s
viewWillLayoutSubviews
method is called.调用视图控制器的viewWillLayoutSubviews
The view’s
layoutSubviews
method is called. If autolayout is used to configure the view hierarchy, it updates the layout constraints by executing the following steps:调用视图的
layoutSubviews 方法。如果使用了自动布局来配置视图层次,它通过执行以下步骤来更新布局常量。
The view controller’s
updateViewConstraints
method is called.调用视图控制器的
updateViewConstraints 方法。
The
UIViewController
class’s implementation of theupdateViewConstraints
method calls the view’supdateConstraints
method.实现UIViewController 类的updateViewConstraints 方法调用视图的
updateConstraints方法。
After the layout constraints are updated, a new layout is calculated and the views are repositioned.
布局常量更新以后,一个新布局被计算并且视图被重新定位。
The view controller’s
viewDidLayoutSubviews
method is called.调用视图控制器的viewDidLayoutSubviews 方法。
Ideally, the views themselves perform all of the necessary work to reposition themselves, without requiring the view controller to participate in the process at all. Often, you can configure the layout entirely within Interface Builder. However, if the view controller adds and removes views dynamically, a static layout in Interface Builder may not be possible. In this case, the view controller is a good place to control the process, because often the views themselves only have a limited picture of the other views in the scene. Here are the best approaches to this in your view controller:
理论上说,视图本身执行所有必要的工作来重新定位它们自己,而不需要视图控制器参与该过程。 你常常可以在界面生成器里配置整个布局。然而,如果视图控制器动态地添加和删除视图,界面生成器中的一个静态布局不可能完成该工作。在这种情况下,视图控制器是控制该过程的一个好地方,因为屏幕中视图本身常常只有其他视图的有限图片。 以下是在你的视图控制器上完成该工作的最好方法:
Use layout constraints to automatically position the views (iOS 6 and later). You override
updateViewConstraints
to add any necessary layout constraints not already configured by the views. Your implementation of this method must call[super updateViewConstraints]
.For more information on layout constraints, see Auto Layout Guide.
使用布局常量来自动定位视图(iOS 6 及以后版本). 重写updateViewConstraints 方法来添加任何必要的视图没有配置的布局常量。该方法的实现必须调用
[super updateViewConstraints]
. 更多布局常量的信息,请看 Auto Layout Guide.Use a combination of autoresizing masks and code to manually position the views (iOS 5.x). You override
layoutSubviews
and use it to reposition any views whose positions cannot be set automatically through the use of resizing masks.For more information on the autoresizing properties of views and how they affect the view, see View Programming Guide for iOS.
使用自动调整尺寸蒙版和代码的组合来手动定位视图(iOS 5.x). 重写layoutSubviews 方法并使用它来定位任何视图,这些视图的位置不能通过使用重新调整尺寸蒙版来自动设置。 更多关于视图的自动调整尺寸特性以及它们如何影响视图的信息,请看 View Programming Guide for iOS.
View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views的更多相关文章
- 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---(四)---Creating Custom Content View Controllers
Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...
- View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views
Views Because view objects are the main way your application interacts with the user, they have many ...
- 【IOS笔记】View Programming Guide for iOS -1
原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...
- View Programming Guide for iOS ---- iOS 视图编程指南(五)---Animations
Animations Animations provide fluid visual transitions between different states of your user inter ...
- View Programming Guide for iOS ---- iOS 视图编程指南(二)---View and Window Architecture
View and Window Architecture 视图和窗口架构 Views and windows present your application’s user interface and ...
- View Programming Guide for iOS ---- iOS 视图编程指南(一)
Next About Windows and Views 关于窗口和视图 In iOS, you use windows and views to present your application’s ...
- Table View Programming Guide for iOS---(四)---Navigating a Data Hierarchy with Table Views
Navigating a Data Hierarchy with Table Views 导航数据表视图层次 A common use of table views—and one to which ...
- 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 ...
随机推荐
- 【docker】启动docker连接数据库 出现FATAL: password authentucation failed for user "homestatead"问题
docker可以成功启动,启动命令如下: docker run -d -p : -v `pwd`/pgdata:/var/lib/postgresql/data -e POSTGRES_USER=ho ...
- yum gd linux
32位操作系统安装命令:[root@localhost ~]# yum install php-gd*64位操作系统安装命令:[root@localhost ~]# yum install php-g ...
- 【嵌入式Linux+ARM】GPIO操作
1.GPIO介绍 GPIO(general purpose i/o ports)意思为通用输入/输出端口,通俗的说就是一些引脚. 我们可以通过它们输出高低电平 或 读入引脚的状态. s3c2440中有 ...
- 【Objective-C】09-空指针和野指针
一.什么是空指针和野指针 1.空指针 1> 没有存储不论什么内存地址的指针就称为空指针(NULL指针) 2> 空指针就是被赋值为0的指针.在没有被详细初始化之前.其值为0. 以下两个都是空 ...
- poj 2828 Buy Tickets 【线段树点更新】
题目:id=2828" target="_blank">poj 2828 Buy Tickets 题意:有n个人排队,每一个人有一个价值和要插的位置,然后当要插的位 ...
- HTML5已定稿:将彻底颠覆原生应用
2007年W3C(万维网联盟)立项HTML5,直至2014年10月底.这个长达八年的规范最终正式封稿. 过去这些年.HTML5颠覆了PC互联网的格局,优化了移动互联网的体验,接下来.HTML5将颠覆原 ...
- C#语言循环语句for嵌套
- Computer form factor
http://en.wikipedia.org/wiki/Motherboard_form_factor Computer form factor From Wikipedia, the free e ...
- javascript参数arguments对象
ECMAScript函数的参数与大多树其他语言中函数的参数有所不同.ECMAScript函数不介意传递进来多少个参数,也不在乎传进来参数是什么类型.函数体是通过arguments对象来访问参数数组.a ...
- appium部分api
转自:http://www.aichengxu.com/view/41510 使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建 ...