iOS之UITraitCollection

UITraitCollection

為表征 size class 而生,用來區分設備。你可以在它身上獲取到足以區分所有設備的特征。

UITraitEnvironment 協議、UIContentContainer 協議

UIViewController 遵循了這兩個協議,用來監聽和設置 traitCollection 的變化。

@protocol UITraitEnvironment <NSObject>@property (nonatomic, readonly) UITraitCollection *traitCollection NS_AVAILABLE_IOS(8_0);/*! To be overridden as needed to provide custom behavior when the environment's traits change. */
- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection NS_AVAILABLE_IOS(8_0);
@end

UIViewController 對 UIContentContainer 協議提供了默認的實現。我們自定義 ViewController 的時候可以重寫這些方法來調整視圖布局,比如我們可以在這些方法里調整 ChildViewControler 的位置。當我們重寫這些協議方法時,我們通常都去調用 super。

@protocol UIContentContainer <NSObject>preferredContentSize 在 UIContentContainer 協議中是只讀的,對應的 UIViewController 有可寫的版本。我們可以使用 preferredContentSize 來設置我們期望的 ChildViewController 的界面大小。舉個例子,如果應用中使用的 popOver 大小會發生變化,iOS7 之前我們可以用 contentSizeForViewInPopover 來調整。iOS7 開始這個 API 被廢棄,我們可以使用 preferredContentSize 來設置。當一個容器 ViewController 的 ChildViewController 的這個值改變時,UIKit 會調用 preferredContentSizeDidChangeForChildContentContainer 這個方法告訴當前容器 ViewController 。我們可以在這個方法里根據新的 Size 對界面進行調整。@property (nonatomic, readonly) CGSize preferredContentSize NS_AVAILABLE_IOS(8_0);- (void)preferredContentSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container NS_AVAILABLE_IOS(8_0);/*
Intended as a bridge for a view controller that does not use auto layout presenting a child that does use auto layout.If the child's view is using auto layout and the -systemLayoutSizeFittingSize: of the view
changes, -systemLayoutFittingSizeDidChangeForChildContentContainer: will be sent to the view controller's parent.
*/
- (void)systemLayoutFittingSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container NS_AVAILABLE_IOS(8_0);/*
When the content container forwards viewWillTransitionToSize:withTransitionCoordinator: to its children, it will call this method to determine what size to send them. If the returned size is the same as the child container's current size, viewWillTransitionToSize:withTransitionCoordinator: will not be called.設置 ChildViewController 的 size。當容器ViewControllerviewWillTransitionToSize:withTransitionCoordinator:被調用時(我們重寫這個方法時要調用 super),sizeForChildContentContainer 方法將會被調用。然后我們可以把需要設置的 size 發送給 ChildViewController。當我們設置的這個 size 和當前 ChildViewController 的 size 一樣,那么 ChildViewController 的 viewWillTransitionToSize 方法將不會被調用。默認的實現是返回 parentSize。
*/
- (CGSize)sizeForChildContentContainer:(id <UIContentContainer>)container withParentContainerSize:(CGSize)parentSize NS_AVAILABLE_IOS(8_0);/* 
This method is called when the view controller's view's size is changed by its parent (i.e. for the root view controller when its window rotates or is resized). If you override this method, you should either call super to propagate the change to children or manually forward the change to children.ViewController 的 View 的 size 被他的 Parent Controller 改變時,會觸發這個方法。(比如rootViewController 在它的 window 旋轉的時候)。我們在重寫這個方法時,確保要調用 super,來保證 size 改變的這條消息能夠正常傳遞給它的 Views 或者 ChildViewControllers。*/
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);/* 
This method is called when the view controller's trait collection is changed by its parent.If you override this method, you should either call super to propagate the change to children or manually forward the change to children.當 ViewController 的 traitCollection 的值將要改變時會調用這個方法。這個方法是在  UITraitEnvironment 協議方法 traitCollectionDidChange: 之前被調用。我們在重寫這個方法時,也要確保要調用 super 來保證消息的傳遞。
*/
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);@end 

?

轉載于:https://www.cnblogs.com/henusyj-1314/p/9928560.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389318.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389318.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389318.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

直方圖繪制與直方圖均衡化實現

一&#xff0c;直方圖的繪制 1.直方圖的概念&#xff1a; 在圖像處理中&#xff0c;經常用到直方圖&#xff0c;如顏色直方圖、灰度直方圖等。 圖像的灰度直方圖就描述了圖像中灰度分布情況&#xff0c;能夠很直觀的展示出圖像中各個灰度級所 占的多少。 圖像的灰度直方圖是灰…

eclipse警告與報錯的修復

1.關閉所有eclipse校驗 windows->perference->validation disable all 2.Access restriction: The constructor BASE64Decoder() is not API (restriction on required library C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar) 在builde path 移除jre&#xff0c;再…

時間序列因果關系_分析具有因果關系的時間序列干預:貨幣波動

時間序列因果關系When examining a time series, it is quite common to have an intervention influence that series at a particular point.在檢查時間序列時&#xff0c;在特定時間點對該序列產生干預影響是很常見的。 Some examples of this could be:例如&#xff1a; …

微生物 研究_微生物監測如何工作,為何如此重要

微生物 研究Background背景 While a New York Subway station is bustling with swarms of businessmen, students, artists, and millions of other city-goers every day, its floors, railings, stairways, toilets, walls, kiosks, and benches are teeming with non-huma…

Linux shell 腳本SDK 打包實踐, 收集assets和apk, 上傳FTP

2019獨角獸企業重金招聘Python工程師標準>>> git config user.name "jenkins" git config user.email "jenkinsgerrit.XXX.net" cp $JENKINS_HOME/maven.properties $WORKSPACE cp $JENKINS_HOME/maven.properties $WORKSPACE/app cp $JENKINS_…

opencv:卷積涉及的基礎概念,Sobel邊緣檢測代碼實現及卷積填充模式

具體參考我的另一篇文章&#xff1a; opencv:卷積涉及的基礎概念&#xff0c;Sobel邊緣檢測代碼實現及Same&#xff08;相同&#xff09;填充與Vaild&#xff08;有效&#xff09;填充 這里是對這一篇文章的補充&#xff01; 卷積—三種填充模式 橙色部分為image, 藍色部分為…

怎么查這個文件在linux下的哪個目錄

因為要裝pl/sql所以要查找tnsnames.ora文件。。看看怎么查這個文件在linux下的哪個目錄 find / -name tnsnames.ora 查到&#xff1a; /opt/app/oracle/product/10.2/network/admin/tnsnames.ora/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora 還可以用loca…

無法從套接字中獲取更多數據_數據科學中應引起更多關注的一個組成部分

無法從套接字中獲取更多數據介紹 (Introduction) Data science, machine learning, artificial intelligence, those terms are all over the news. They get everyone excited with the promises of automation, new savings or higher earnings, new features, markets or te…

web數據交互_通過體育運動使用定制的交互式Web應用程序數據科學探索任何數據...

web數據交互Most good data projects start with the analyst doing something to get a feel for the data that they are dealing with.大多數好的數據項目都是從分析師開始做一些事情&#xff0c;以便對他們正在處理的數據有所了解。 They might hack together a Jupyter n…

C# .net 對圖片操作

using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;public class ImageHelper{/// <summary>/// 獲取圖片中的各幀/// </summary>/// <param name"pPath">圖片路徑</param>/// <param name"pSaveP…

數據類型之Integer與int

數據類型之Integer與int Java入門 基本數據類型 眾所周知&#xff0c;Java是面向對象的語言&#xff0c;一切皆對象。但是為了兼容人類根深蒂固的數據處理習慣&#xff0c;加快常規數據的處理速度&#xff0c;提供了9種基本數據類型&#xff0c;他們都不具備對象的特性&#xf…

PCA(主成分分析)思想及實現

PCA的概念&#xff1a; PCA是用來實現特征提取的。 特征提取的主要目的是為了排除信息量小的特征&#xff0c;減少計算量等。 簡單來說&#xff1a; 當數據含有多個特征的時候&#xff0c;選取主要的特征&#xff0c;排除次要特征或者不重要的特征。 比如說&#xff1a;我們要…

【安富萊二代示波器教程】第8章 示波器設計—測量功能

第8章 示波器設計—測量功能 二代示波器測量功能實現比較簡單&#xff0c;使用2D函數繪制即可。不過也專門開辟一個章節&#xff0c;為大家做一個簡單的說明&#xff0c;方便理解。 8.1 水平測量功能 8.2 垂直測量功能 8.3 總結 8.1 水平測量功能 水平測量方…

深度學習數據更換背景_開始學習數據科學的最佳方法是了解其背景

深度學習數據更換背景數據科學教育 (DATA SCIENCE EDUCATION) 目錄 (Table of Contents) The Importance of Context Knowledge 情境知識的重要性 (Optional) Research Supporting Context-Based Learning (可選)研究支持基于上下文的學習 The Context of Data Science 數據科學…

熊貓數據集_用熊貓掌握數據聚合

熊貓數據集Data aggregation is the process of gathering data and expressing it in a summary form. This typically corresponds to summary statistics for numerical and categorical variables in a data set. In this post we will discuss how to aggregate data usin…

IOS CALayer的屬性和使用

一、CALayer的常用屬性 1、propertyCGPoint position; 圖層中心點的位置&#xff0c;類似與UIView的center&#xff1b;用來設置CALayer在父層中的位置&#xff1b;以父層的左上角為原點&#xff08;0&#xff0c;0&#xff09;&#xff1b; 2、 property CGPoint anchorPoint…

GridView詳解

快速預覽&#xff1a;GridView無代碼分頁排序GridView選中&#xff0c;編輯&#xff0c;取消&#xff0c;刪除GridView正反雙向排序GridView和下拉菜單DropDownList結合GridView和CheckBox結合鼠標移到GridView某一行時改變該行的背景色方法一鼠標移到GridView某一行時改變該行…

訪問模型參數,初始化模型參數,共享模型參數方法

一. 訪問模型參數 對于使用Sequential類構造的神經網絡&#xff0c;我們可以通過方括號[]來訪問網絡的任一層。回憶一下上一節中提到的Sequential類與Block類的繼承關系。 對于Sequential實例中含模型參數的層&#xff0c;我們可以通過Block類的params屬性來訪問該層包含的所有…

QZEZ第一屆“飯吉圓”杯程序設計競賽

終于到了飯吉圓杯的開賽&#xff0c;這是EZ我參與的歷史上第一場ACM賽制的題目然而沒有罰時 不過題目很好&#xff0c;舉辦地也很成功&#xff0c;為法老點贊&#xff01;&#xff01;&#xff01; 這次和翰爺&#xff0c;吳駿達 dalao&#xff0c;陳樂揚dalao組的隊&#xff0…

談談數據分析 caoz_讓我們談談開放數據…

談談數據分析 caozAccording to the International Open Data Charter(1), it defines open data as those digital data that are made available with the technical and legal characteristics necessary so that they can be freely used, reused and redistributed by any…