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.pswp.cn/news/260702.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/260702.shtml
英文地址,請注明出處:http://en.pswp.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…