在iOS 10~ 11系统上,莫名其妙发现一个crash, iOS 12系统没事(iOS 12系统做了优化么?)。 定位发现是[self layoutIfNeeded]
崩溃到这句代码上。
原因: layoutIfNeeded 方法必须在主线程执行。
所以对UIView 的setNeedsLayout,layoutIfNeeded,layoutSubviews,setNeedsUpdateConstraints方法执行要在主线程,不在主线程的要dispatch到主线程执行
dispatch_async(dispatch_get_main_queue(), ^{
[self layoutIfNeeded];
});
查找过程
1.运行程序,界面卡死,然后点击xcode上

2.在控制台输入:bt,查看堆栈信息

3.也可以直接在xcode上查看堆栈信息

4.根据打印出的堆栈信息,定位到问题点

5.修复。 将[self layoutIfNeeded]; 放到主线程更新解决。
小tips
xcode里模糊搜索方法
正则匹配搜索方法
eg:搜索gearbest

结果:
加正则匹配搜索:



网友评论