contentInsetAdjustmentBehavior各个值之间的区别
iOS11也出了不少时候了网上说适配的文章一大堆。
关于contentInsetAdjustmentBehavior这个参数之间的区别,好像没什么人能说明。
往下看的前提是你已经知道什么是安全区域,没看明白这个请出门左转WWDC2017编号204(16分20秒开始)。
以下内容是基于腾讯Bugly的iOS 11 安全区域适配总结内容扩展而来。(原文网址:https://mp.weixin.qq.com/s/W1_0VrchCO50owhJNmJnuQ)
这里写了个Demo目的是解释清楚contentInsetAdjustmentBehavior这个参数的值都是干啥的。
这个Demo的基本原则就是列出所有ScrollView的ContentSize和SaveArea的关系。
github地址:
https://github.com/biosli/ScrollViewContentInsetAdjustmentBehaviorDemo
基础代码
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame: self.view.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; UIImage *testImg = [UIImage imageNamed: @"aaaa"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: testImg]; [self.view addSubview: scrollView];
简单叙述页面关系:
就是一个ViewController里面放一个ScrollView,ScrollView里面包含了一个UIImageView。aaaa是张大图。
一、UIScrollViewContentInsetAdjustmentScrollableAxes
例1:
//以下全部例子,请在iPhoneX模拟器上查看。
//UIScrollViewContentInsetAdjustmentScrollableAxes例1
//如果scrollView的ContentSize很小,则不考虑安全区域
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;
imageView.frame = frame;
[scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentScrollableAxes;
例1图:
这两个地方忽略了安全区域。
例2:
//UIScrollViewContentInsetAdjustmentScrollableAxes例子2,横屏查看
//如果scrollView的ContentSize大于超出显示范围,则计算安全区域
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;//图片拉长,超出屏幕范围
imageView.frame = frame;
[scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentScrollableAxes;
例2图:
被拉长了,纵向可以滚动,横向宽度不够不能滚动。
红色是横向方向,不可滚动,安全区域被忽略。
例3:
//UIScrollViewContentInsetAdjustmentScrollableAxes例子3,接上例,横屏查看
//如果强制横向滚动,则计算安全区域
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;//图片拉长,超出屏幕范围
imageView.frame = frame;
[scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size;
//强制横向滚动
scrollView.alwaysBounceHorizontal = YES; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentScrollableAxes;
例3图:
强制横向滚动,两个方向的安全区域都会被考虑到。
二、UIScrollViewContentInsetAdjustmentAutomatic
//UIScrollViewContentInsetAdjustmentAutomatic例子,横屏查看
//对照UIScrollViewContentInsetAdjustmentScrollableAxes例1
//就算不够高度,也会空出上下两部分的安全区域。
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;
imageView.frame = frame;
[scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
例图:
图片很小,不够撑满屏幕,但是用这个参数,会空出上下方向的安全区域。
其他的行为与UIScrollViewContentInsetAdjustmentScrollableAxes一致。
三、UIScrollViewContentInsetAdjustmentNever
//UIScrollViewContentInsetAdjustmentNever例子
//完全不考虑安全区域
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;
imageView.frame = frame; [scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
例图:
Never了就是都不考虑安全区域了。
四、UIScrollViewContentInsetAdjustmentAlways
//UIScrollViewContentInsetAdjustmentAlways例子
//不管内容,全部考虑安全区域
CGRect frame = imageView.frame;
frame.size.width = ;
frame.size.height = ;
imageView.frame = frame; [scrollView addSubview: imageView]; scrollView.contentSize = imageView.frame.size; scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
例图:
不管内容够不够大,全部考虑安全区域。
(对比UIScrollViewContentInsetAdjustmentScrollableAxes例1和UIScrollViewContentInsetAdjustmentAutomatic例子)
以下是适配建议:
对于完全自定义页面的安全区域是个碍事的东西,把ScrollView(及子类)的contentInsetAdjustmentBehavior设置成Never,自己控制每一个细节。
对于没有横屏需求的同学,系统默认的UIScrollViewContentInsetAdjustmentAutomatic是个好选择,就不用使用者自己修改了。
对于有横屏需求的同学,建议使用UIScrollViewContentInsetAdjustmentAlways,横屏的时候不会被“刘海”干扰。
PS:后面是一些有趣的阴谋论,关于为什么苹果放弃了之前的automaticallyAdjustsScrollViewInsets而强制使用新的SafeArea。
iOS 11是6月WWDC发布的,那时候这个接口(automaticallyAdjustsScrollViewInsets)就被禁掉了。9月份iPhoneX发布。
当时,大家只知道苹果换了一套布局体系。
从程序员角度看,6月份大家开始动手适配iOS11,开发人员不明所以,唾弃新体系的种种不便。9月份发布新的屏幕尺寸,新的体系发挥了价值,乖乖听话的开发人员已经适配完成了。
从苹果角度看,6月份发布了新体系,但并没有透露新体系对新机型出来以后对适配的影响。9月份出新手机了,然后得意的看着开发者“叫你们丫不早适配”。
这是一个中间组件提供方,强制修改接口的一个好办法。开发人员应该老老实实听苹果粑粑的话趁热适配新的iOS系统,而且要详细看每一个与老系统的对比,优先进行适配。
contentInsetAdjustmentBehavior各个值之间的区别的更多相关文章
- 编写高质量代码改善C#程序的157个建议——建议28:理解延迟求值和主动求值之间的区别
建议28:理解延迟求值和主动求值之间的区别 要理解延迟求值(lazy evaluation)和主动求值(eager evaluation),先看个例子: List<, , , , , , , , ...
- C# 如何捕获键盘按钮和组合键以及KeyPress/KeyDown事件之间的区别 (附KeyChar/KeyCode值)
1. 首先将窗口属性KeyPreview设为true,如果属性对话框中找不到,就直接在代码里添加: 2. 添加KeyPress / KeyDown事件: 1.KeyPress 和KeyDown .Ke ...
- 你真的会玩SQL吗?EXISTS和IN之间的区别
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- [转]ExtJs基础--Html DOM、Ext Element及Component三者之间的区别
要学习及应用好Ext框架,必须需要理解Html DOM.Ext Element及Component三者之间的区别. 每一个HTML页面都有一个层次分明的DOM树模型,浏览器中的所有内容都有相应的DOM ...
- iOS中assign,copy,retain之间的区别以及weak和strong的区别
@property (nonatomic, assign) NSString *title; 什么是assign,copy,retain之间的区别? assign: 简单赋值,不更改索引计数(Refe ...
- javascrip中parentNode和offsetParent之间的区别
首先是 parentNode 属性,这个属性好理解,就是在 DOM 层次结构定义的上下级关系,如果元素A包含元素B,那么元素B就可以通过 parentElement 属性来获取元素A. 要明白 off ...
- 面试问题5:const 与 define 宏定义之间的区别
问题描述:const 与 define 宏定义之间的区别 (1) 编译器处理方式不同 define宏是在预处理阶段展开: const常量是编译运行阶段使用: (2) 类型和安全检查不同 ...
- 关于背景图相对父容器垂直居中问题 —— vertical-align 和 line-height 之间的区别
html css <div class="register-wrapper"> <div class="register"> &l ...
- 答:SQLServer DBA 三十问之一: char、varchar、nvarchar之间的区别(包括用途和空间占用);xml类型查找某个节点的数据有哪些方法,哪个效率高;使用存储 过程和使用T-SQL查询数据有啥不一样;
http://www.cnblogs.com/fygh/archive/2011/10/18/2216166.html 1. char.varchar.nvarchar之间的区别(包括用途和空间占用) ...
随机推荐
- 为什么重写equals还要重写hashcode??
equals和hashcode是object类下一个重要的方法,而object类是所有类的父类,所以所有的类都有这两个方法 equals和hashcode间的关系: 1.如果两个对象相同(即equal ...
- day37
今日内容 1.线程池和进程池 2.利用线程池实现套接字并发通信 3.协程(利用模块gevent模块,实现单线程下套接字并发通信) 1.线程池与进程池 要用线程池与进程池,首先要导入concurrent ...
- python_基础语法
开始正式接触python的语法: 1. 2.
- 大数据入门第十二天——flume入门
一.概述 1.什么是flume 官网的介绍:http://flume.apache.org/ Flume is a distributed, reliable, and available servi ...
- C# read write ini file
[DllImport("kernel32")] private static extern long WritePrivateProfileString(string sectio ...
- 20155234 昝昕明 《网络对抗技术》实验一 PC平台逆向破解
实践内容: 手工修改可执行文件,改变程序执行流程,直接跳转到getShell函数. 利用foo函数的Bof漏洞,构造一个攻击输入字符串,覆盖返回地址,触发getShell函数. 注入一个自己制作的sh ...
- 20155308《信息安全系统设计基础 嵌入式C语言课堂考试补博客
20155308<信息安全系统设计基础 嵌入式C语言课堂考试补博客 知识点 置位 ?bits = bits | (1 << 7) ; /* sets bit 7 */ bits |= ...
- 访问kubernetes ingress-controller
ingress-controller可以理解为一套反向代理系统,本身需要暴露端口到集群外部,以便客户端访问. 根据实际使用,给出两种暴露端口的方式,如下: 方案一 拓扑 说明 ingress-cont ...
- nginx反向代理tomcat应用,struts2网站程序redirect时导致请求地址错误的解决方法
一个使用struts2的网站在登录页面需要进行redirect跳转,大致如下: <package name="admin" extends="httl-defaul ...
- PAT甲题题解-1008. Elevator (20)-大么个大水题,这也太小瞧我们做题者的智商了
如题... #include <iostream> #include <cstdio> #include <algorithm> #include <cstr ...