IOS10上崩溃错误“View has lost track of its superview, most likely through unsupported use of CALayer”解决方案
来源:互联网 发布:阿里云域名过户步骤 编辑:程序博客网 时间:2024/06/15 18:51
为了适配iOS 10 升级了Xcode 8,项目中点击cell中的一个按钮就崩溃了。
崩溃日志:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'View has lost track of its superview, most likely through unsupported use of CALayer API on the view's layer. If this isn't a crash yet, it will be in the near future.
Problem view: <UIToolbar: 0x1018555d0; frame = (0 0; 0 0); layer = <CALayer: 0x17023f520>>Expected parent: <AMBlurView: 0x1018697c0; frame = (0 0; 320 160); clipsToBounds = YES; alpha = 0.8; autoresize = W+H; layer = <CALayer: 0x17023f1e0>>
Break on UIViewReportBrokenSuperviewChain to debug.'
在谷歌上找到了问题的原因,如下所示:
这是insertsublayer问题。这是一种把戏获得透明度的背景。显然这是一个已知的把戏,但这使得应用程序崩溃在新的一个。
在项目中找到了问题代码,是因为我写的视频播放器要在播放时在底层添加一个模糊背景图片,我是像下面这样写的
//当播放的时候在底层设置图片(填充播放剩余的部分)
self.beiJingImageView = [[UIImageView alloc]initWithFrame:self.layer.bounds];
[self.layer insertSublayer:_beiJingImageView.layer below:_playerLayer];
//给背景图片添加模糊效果
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
self.effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
self.effectView.frame = self.beiJingImageView.bounds;
//设置模糊透明度
self.effectView.alpha = .8f;
[self.beiJingImageView addSubview:self.effectView];
引起崩溃的代码就是下面代码
self.beiJingImageView = [[UIImageView alloc]initWithFrame:self.layer.bounds];
[self.layer insertSublayer:_beiJingImageView.layer below:_playerLayer];
所以换了新的实现方式
//先设置模糊层
UIView *mohuView = [[UIViewalloc]initWithFrame:self.layer.bounds];
mohuView.backgroundColor = [UIColorblackColor];
mohuView.alpha =0.8;
[selfaddSubview:mohuView];
[selfsendSubviewToBack:mohuView];
// //当播放的时候在底层设置图片(填充播放剩余的部分)
self.beiJingImageView = [[UIImageViewalloc]initWithFrame:self.layer.bounds];
self.beiJingImageView.contentMode =UIViewContentModeScaleAspectFit;
[selfaddSubview:self.beiJingImageView];
[selfsendSubviewToBack:self.beiJingImageView];
这就是我的这个崩溃的解决方式,如果正好你碰到了,正好可以尝试这个方法解决一下
- IOS10上崩溃错误“View has lost track of its superview, most likely through unsupported use of CALayer”解决方案
- Sqlite3错误:Recursive use of cursors not allowed 的解决方案
- use of list view and tree view
- Keep track of
- Track of weekend
- ORA-15027: active use of diskgroup "TEST" precludes its dismount
- 错误码: 1418 This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- Kind of lost
- Study Note of use of MessageBox() and its surrounding information(MFC)
- [常见错误 及 解决方案系列]USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"
- [常见错误 及 解决方案系列]USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"
- Keep track of the median?
- hdu5476Explore Track of Point+平面几何
- 常用机器学习算法总结
- Spring Security3 - MVC 整合教程 (初识Spring Security3)
- HTML5
- 华为35
- ajaxForm和ajaxSubmit 粘贴就可用
- IOS10上崩溃错误“View has lost track of its superview, most likely through unsupported use of CALayer”解决方案
- mui 区域滚动
- Android ViewStub归纳
- Git的常用撤销技巧
- 关于Jquery中json的使用
- 函数与程序结构 例题
- Fragment入门
- LinearLayout中的weight属性的计算
- java 用http发post请求