Client error attempting to change layout margins of a private view
从 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的更多相关文章
- 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 ...
- 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 ...
- Cisco VPN Client Error 56解决
Cisco VPN Client Error 56解决 VPN Client报错 650) this.width=650;" style="width:575px;height:1 ...
- 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 ...
- axis client error Bad envelope tag: definitions
http://blog.csdn.net/lifuxiangcaohui/article/details/8090503 ——————————————————————————————————————— ...
- docker升级后启动报错400 Client Error: Bad Request ("Unknown runtime specified docker-runc")
宝塔面板docker升级后启动容器时报错400 Client Error: Bad Request ("Unknown runtime specified docker-runc" ...
- Error attempting to get column from result set
当使用mybatis plus3.2.0+springboot2.1.1 报错 Error attempting to get column from result set 1.一般出现这种问题,最简 ...
- 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 ...
- 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 ...
随机推荐
- Requests小技巧
- HTML+CSS的小实例
通过一个月以来对HTML5+CSS的学习.这篇随笔给大家来做一个简单的网页中常见的导航栏. 这些都称之为网页中的导航栏. 我简单的做了一个某宝和58同城的导航栏,供大家学习参考. 一.58同城导航栏: ...
- ruby2.2 DevKit 安装后无法使用解决方案
windows 系统下,Ruby 的某些 gem 包需要 DevKit 才能正常安装,2.4 以后的版本可以一键安装 DevKit,之前的版本只能手动安装. 2.4 以后的可以到官网下载:https: ...
- Python文本转化语音模块大比拼,看看青铜与王者的差别!
文本转语音 如果把Python比喻成游戏中的一个英雄,你觉得它是谁?对于Dota老玩家来说,我会想到钢琴手卡尔!感觉Python和卡尔一样,除了生孩子什么都可以做的角色.日常生活中,我们会涉及到很多语 ...
- virtualenv 在windows下的简单应用
https://docs.python.org/zh-cn/3/tutorial/venv.html cmd下的操作: pip install virtualenv pip install virt ...
- Xcode11 踩坑记录
1.UITextView控件莫名导致崩溃 如上图所示,点击Step over 前进进入编译器内部 在lldb控制台输入指令 po $arg1 看到编译器给的提示是由于UITextView的问题. 解决 ...
- iOS-使用Xcode自带单元测试UnitTest
![Uploading QQ20160129-3_262826.png . . .]####什么是单元测试?一听到单元测试这个词感觉很高端,其实单元测试就是为你的方法多专门写一个测试函数.以保证你的方 ...
- unix环境高级编程中的err_quit,err_sys用到的知识点
unix环境高级编程中的err_quit,err_sys 环境 os CentOS release 6.7 (Final) gcc 4.4.7 c语言预备知识 标准输入输出文件 在linux系统中一切 ...
- latex常用技巧
画表格 \usepackage{multirow} \begin{tabular}{cccc} \hline \multicolumn{4}{c}{学生信息}\\ \hline 班级& 姓名& ...
- C# 利用反射更改父类公开对象
需求 : 有一个保存数据库字段的基础类,现在要加个状态返回给前端,但是又不能改基础类: class BaseA { public string Name { get; set; } } class A ...