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). 然而,视图控制器也在不同点被调用,这样它就可以参与进程。以下是发生的事情:

  1. The view controller’s view is resized to the new size.

    视图控制器的尺寸被重新设置为新尺寸。

  2. If autolayout is not in use, the views are resized according to their autoresizing masks.

    如果没有使用自动布局,视图根据它们的自动调整尺寸蒙版来调整尺寸。

  3. The view controller’s viewWillLayoutSubviews method is called.

    调用视图控制器的viewWillLayoutSubviews

  4. 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 方法。如果使用了自动布局来配置视图层次,它通过执行以下步骤来更新布局常量。

    1. The view controller’s updateViewConstraints method is called.

      调用视图控制器的 updateViewConstraints 方法。

    2. The UIViewController class’s implementation of the updateViewConstraints method calls the view’s updateConstraints method.

      实现UIViewController 类的updateViewConstraints 方法调用视图的updateConstraints方法。

    3. After the layout constraints are updated, a new layout is calculated and the views are repositioned.

      布局常量更新以后,一个新布局被计算并且视图被重新定位。

  5. The view controller’s viewDidLayoutSubviewsmethod 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

转载于:https://www.cnblogs.com/patientAndPersist/p/3557387.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/260702.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于百度地图js进行地理定位

http://www.mengxiangchaoren.com/jquery.select.position.min.js 使用方法 $("#myCity").renderSelect({posByGps:true,bdAk:BD_AK});转载于:https://www.cnblogs.com/Brose/p/jquery_select_position.html

C#接口-接口作用

C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正认识到接口的作用的时候就…

gpio的8种工作模式_Stm32之GPIO工作模式简介

GPIO的8种工作模式GPIO初始化结构体的时候,必须要配置合适的工作模式,这样才能使得IO口发挥应有的作用。工作模式大体上共分为输入输出两类,共8种,下面将介绍这8种工作模式。GPIO工作模式输入模式GPIO_Mode_AIN 模拟输入 GPIO_Mod…

vagrant,流浪汉,我又来啦。

最近学个DEVOPS2.0,讲微服务,容器华,持续部署,很到位,就一个一个工具撸一撸。。。 vagrant,以前接触过,所以上手快,,哈哈,,用时再具体配置。 virt…

dedecms最新版本修改任意管理员漏洞

此漏洞无视gpc转义,过80sec注入防御。 补充下,不用担心后台找不到。这只是一个demo,都能修改任意数据库了,还怕拿不到SHELL? 起因是全局变量$GLOBALS可以被任意修改,随便看了下,漏洞一堆&#x…

第4章 Python 数字图像处理(DIP) - 频率域滤波10 - 使用低通频率域滤波器平滑图像 - 理想、高斯、巴特沃斯低通滤波器

目录使用低通频率域滤波器平滑图像理想低通滤波器(ILPF)高斯低通滤波器(GLPF)巴特沃斯低通滤波器低通滤波的例子使用低通频率域滤波器平滑图像 理想低通滤波器(ILPF) 在以原点为中心的一个圆内无衰减地通过所有频率,而在这个圆外“截止”所有的频率的二维低通滤波…

vs2008中combox用法总结

1、判断是否为空 m_CheckPoint.GetCurSel()-1; 2、清空 m_CheckPoint.ResetContent(); 3、添加 m_CheckPoint.AddString(str); 4、获取某一索引的值 m_CheckPoint.GetLBText(j,str1);//j为索引,str1为存储变量 5、删除某一索引的值 m_CheckPoint.DeleteString(j);//…

bluecam连接步骤说明_厂家详解旋片式真空泵使用说明

旋片式真空泵是有区分单双极高速直联结构的真空泵,是用来对密封容器抽除气体的基本设备之一。旋片式真空泵的泵与电机连轴,有着高转速、外型小、结构紧凑、流动性工作方便的优点。本文所使用旋片式真空泵使用说明资料,是台冠真空泵技术团队工…

python函数中可变参数的传递方式是_Python函数可变参数定义及其参数传递方式实例详解...

本文实例讲述了Python函数可变参数定义及其参数传递方式。分享给大家供大家参考。具体分析如下: python中 函数不定参数的定义形式如下: 1、func(*args) 传入的参数为以元组形式存在args中,如: def func(*args): print args >&…

加载中做法

一个网页在加载时,可给静态部分加个加载中,而动态部分也即是真正内容用jq来改,这样就有那个效果了转载于:https://www.cnblogs.com/yedeying/p/3618815.html

Junit4常用注解

Junit4注解 JUnit4的测试类不用再继承TestCase类了。使用注解会方便很多。 Before:初始化方法After:释放资源Test:测试方法,在这里可以测试期望异常和超时时间Ignore:忽略的测试方法BeforeClass:针对所有测…

第4章 Python 数字图像处理(DIP) - 频率域滤波11 - 使用高通滤波器锐化图像

目录使用高通滤波器锐化图像由低通滤波器得到理想、高斯和巴特沃斯高通滤波器指纹增强频域中的拉普拉斯钝化掩蔽、高提升滤波和高频强调滤波同态滤波使用高通滤波器锐化图像 由低通滤波器得到理想、高斯和巴特沃斯高通滤波器 HHP(u,v)1−HLP(u,v)(4.118)H_{HP}(u, v) 1 - H_{…

值类型 引用类型 堆栈 堆 之 异想

看了很多值类型 和 引用类型的文章(谷歌能搜索出来的)看了越多疑问越大,而这些资料中没有具体的说明。问题:1、堆栈 和 堆 分别存于计算机的哪个硬件(CPU缓存,内存,硬盘)&#xff1f…

漫步者lollipods如何调节音量_漫步者MF5扩音器体验:老师值得入手

对于教师职业来说,保护好嗓子是很重要的。每天为学生操劳,频繁的讲课,很多老师都遇上了喉咙沙哑的问题。怎么样才能保护好老师的嗓子呢?“小蜜蜂”是很多老师们的选择,这种扩音器可以挂在腰间,通过麦克风&a…

数据库之间数据转换最快方法

用txt导入的方式是最快的,一般是秒级。 以ACCESS数据库到SQLite数据库为例: 第一步:导出ACCESS数据库到txt文件: 一、将表中数据导出到文本文件(TXT): Select * INTO [TEXT;DATABASEE:\TEMP].TE…

pandas删除某列有空值的行_Python-零基础学习Pandas知识点整理(2)

DataFrame数据的清洗--预处理操作import pandas as pdimport numpy as np#DataFrame数据框行或列的删除#df.drop(labelsNone,axis0,indexNone,columnsNone,levelNone,inplaceFalse,error"raise")#labels 表示需要删除的行或列的标签,多行或多列用列表传入…

JavaScript中的闭包

什么是闭包? 当函数可以记住并访问所在的词法作用域时,就产生了闭包,即使函数是在当前词法作用域之外执行的。下面用一些代码来解释这个定义: function foo() {var a 2;function bar() {console.log(a); // 2}bar(); }foo(); 这…

第4章 Python 数字图像处理(DIP) - 频率域滤波12 - 选择性滤波 - 带阻

目录选择性滤波带阻滤波器和带通滤波器陷波滤波器选择性滤波 处理特定的频带的滤波器称为频带滤波器 带阻滤波器: 若某个频带中的频率被滤除 带通滤波器: 若某个频带中的频率被通过 处理小频率矩形区域的滤波器称为陷波滤波器 陷波带阻滤波器&#x…

command line

对chrome 的IPC 感兴趣,想通过他的单元测试来窥探。 无意中看到有一个command_line 类,因为是第二次碰到 OSG中也有一个command类正好…

[物理学与PDEs]第1章第4节 电磁能量和电磁动量, 能量、动量守恒与转化定律 4.3 电磁能量 (动量) 密度, 电磁能量流 (动量流) 密度...

1. 电磁能量密度: $\cfrac{1}{2}\sex{\ve_0E^2\cfrac{1}{\mu_0}B^2}$. 2. 电磁能量流密度向量: ${\bf S}\cfrac{1}{\mu_0}{\bf E}\times {\bf B}$. 3. 电磁动量密度向量: $\cfrac{1}{c^2}{\bf S}$. 4. 电磁动量流密度张量: $\cfrac{1}{2}\sex{\ve_0E^2\cfrac{1}{\mu_0}B^2}{\bf…