从 iOS 11 开始,UINavigationBar 使用了自动布局,左右两边的按钮到屏幕之间会有 16 或 20 的边距。

为了避免点击到间距的空白处没有响应,通常做法是:定义一个 UINavigationBar 子类,重写 layoutSubviews 方法,在此方法里遍历 subviews 获取 _UINavigationBarContentView,并将其 layoutMargins 设置为 UIEdgeInsetsZero

- (void)layoutSubviews {
[super layoutSubviews]; for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) containsString:@"_UINavigationBarContentView"]) {
subview.layoutMargins = UIEdgeInsetsZero;
break;
}
}
}

然而,这种做法在 iOS 13 中会导致崩溃,崩溃信息如下:

Client error attempting to change layout margins of a private view

  

试图更改私有视图的布局边距时出现错误

解决方案:

使用设置 frame 的方式,让 _UINavigationBarContentView 向两边伸展,从而抵消两边的边距

- (void)layoutSubviews {
[super layoutSubviews]; for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) containsString:@"_UINavigationBarContentView"]) {
if ([UIDevice currentDevice].systemVersion.floatValue >= 13.0) {
UIEdgeInsets margins = subview.layoutMargins;
subview.frame = CGRectMake(-margins.left, -margins.top, margins.left + margins.right + subview.frame.size.width, margins.top + margins.bottom + subview.frame.size.height);
} else {
subview.layoutMargins = UIEdgeInsetsZero;
}
break;
}
}
}

 

Client error attempting to change layout margins of a private view的更多相关文章

  1. 0xc000000f: Error attempting to read the boot configuration data

    Get the fix to “0xc000000f: error attempting to read the boot configuration data” boot error for Win ...

  2. Mybatis使用-Error attempting to get column 'type' from result set. / '255' in column '4' is outside valid range for the datatype TINYINT.

    一.遇到的问题是这样的: [RemoteTestNG] detected TestNG version 6.9.10log4j: Parsing for [root] with value=[DEBU ...

  3. Cisco VPN Client Error 56解决

    Cisco VPN Client Error 56解决 VPN Client报错 650) this.width=650;" style="width:575px;height:1 ...

  4. org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'alarmGroup' from result set. Cause: java.sql.SQLException: Error

    异常展示: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'alarmGroup ...

  5. axis client error Bad envelope tag: definitions

    http://blog.csdn.net/lifuxiangcaohui/article/details/8090503 ——————————————————————————————————————— ...

  6. docker升级后启动报错400 Client Error: Bad Request ("Unknown runtime specified docker-runc")

    宝塔面板docker升级后启动容器时报错400 Client Error: Bad Request ("Unknown runtime specified docker-runc" ...

  7. Error attempting to get column from result set

    当使用mybatis plus3.2.0+springboot2.1.1 报错 Error attempting to get column from result set 1.一般出现这种问题,最简 ...

  8. Hadoop启动错误——ERROR: Attempting to operate on hdfs namenode as root but there is no HDFS_NAMENODE_USER defined. Aborting operation.

    错误如下所示; [root@localhost sbin]# start-all.sh Starting namenodes on [192.168.71.129] ERROR: Attempting ...

  9. hyper-v启动虚拟机时提示“The application encountered an error while attempting to change the state of the machine ‘虚拟机名称'”如何处理?

    1. 找出发生这一问题的事件代号 1.1 在开始菜单中搜索程序Event Viewer并点击进入 1.2 点击路径如下: “Applications and Services Logs > Mi ...

随机推荐

  1. day 27 网路编程 面向对象多继承

    知识补充: 字符串转化为字节 string1  = input(“请输入你的名字”) string1.encode('utf-8') 字节转化为字符串 byte1 = b"alex" ...

  2. Linux三个比较特殊的权限

    Linux还有三个比较特殊的权限,分别是:setuid,setgid,stick bit . -:表示一般文件 d:表示目录文件 l:表示链接文件 b:表示块设备 c:表示字符设备 p:表示管道 s: ...

  3. win到linux的编码问题

    从windows到linux的文件可能存在编码问题时,这是因为,Linux和Windows文本文件的行结束标志不同.在Linux中,文本文件用"\n"表示回车换行,而Windows ...

  4. getElementById()

    getElementById():方法的用途是寻找一个有着给定id属性值得元素: element = document.getElementById(ID); 这个方法将返回一个有着给定id属性值得元 ...

  5. linux虚拟机中FTP匿名访问模式介绍与配置

    FTP分3种访问模式,分别是:匿名访问模式,本地用户模式及虚拟用户模式 匿名访问是一种最不安全的验证模式,任何人都可以无需密码验证就登陆到FTP服务端主机,这 种模式一般只用来保存不重要的公开文件,尤 ...

  6. 查看/设置JVM使用的垃圾收集器

    一.设置垃圾收集器的参数 -XX:+UseSerialGC,虚拟机在Client模式下的默认值,Serial+Serial Old -XX:+UseParNewGC,ParNew+Serial Old ...

  7. ThinkPHP5——模型关联(多对多关联)

    关联定义 多对多关联不像一对一和一对多关联,它还要多建一个中间表用来处理多对多的关联,例如: #城市 create table city ( c_id int primary key AUTO_INC ...

  8. 如何在DevOps中实施连续测试

    在过去的十年中,对软件开发的需求已急剧发展.软件已成为公司获得竞争优势的关键优势,特别是如果您的公司属于SaaS范畴.通过在SDLC中实施瀑布等传统流程,组织现在正在向敏捷过渡,以便以更快的速度在市场 ...

  9. Python文章相关性分析---金庸武侠小说分析-2018.1.16

    最近常听同事提及相关性分析,正巧看到这个google的开源库,并把相关操作与调试结果记录下来. 输出结果: 比较有意思的巧合是黄蓉使出打狗棒,郭靖就用了降龙十八掌,再后测试了名词的解析. 小说集可以百 ...

  10. 基于 HTML5 + WebGL 的 3D 太阳系系统

    前言 近年来随着引力波的发现.黑洞照片的拍摄.火星上存在水的证据发现等科学上的突破,以及文学影视作品中诸如<三体>.<流浪地球>.<星际穿越>等的传播普及,宇宙空间 ...