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.mzph.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…