rtBrokenSuperviewChain由Layer操作引起

rtBrokenSuperviewChain由Layer操作引起

本文介绍了Swift UIViewReportBrokenSuperviewChain由Layer操作引起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将代码迁移到Swift 3后遇到了问题。
我猜iOS10现在引发新问题,实际上与Swift本身无关。

I run into a problem after migrating my code to Swift 3.I guess iOS10 raises new issues now and it's actually not related to Swift itself.

错误:

*** 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: 0x102552d80; frame = (0 0; 375 683); alpha = 0.97; opaque = NO; layer = <CALayer: 0x1700383e0>>
    Expected parent: <MyModelView: 0x10250ecd0; frame = (0 -16; 375 683); hidden = YES; layer = <CALayer: 0x17003d4a0>>
Break on UIViewReportBrokenSuperviewChain to debug.'

触发问题的代码是:

[c presentViewController:tabBarViewController animated:NO completion:^{

负责问题的子代码似乎是:

The sub code responsible for the problem seems to be:

- (void)addBlurView
{
  CGRect viewBounds = [[UIScreen mainScreen]applicationFrame];
  self.myModelView = [[MyModalView alloc] initWithFrame:CGRectMake(viewBounds.origin.x, -16, viewBounds.size.width, viewBounds.size.height+36)];

  if(![self toolbar]) {
    _toolbar = [[UIToolbar alloc] initWithFrame:[self.myModelView bounds]];
    [_toolbar setBarStyle:UIBarStyleBlack];
    _toolbar.alpha = 0.97;
    [self.myModelView.layer insertSublayer:_toolbar.layer atIndex:0];
  }

  [self.view addSubview:self.myModelView];
}


推荐答案

我遇到了这个问题移动到Xcode 8时的库(Material-Controls-For-iOS - MDTextField)。我发现问题来自于一个视图层(没有超视图)被添加到另一个视图的层。

I had this issue with a library when moving over to Xcode 8 (Material-Controls-For-iOS - MDTextField). I found that the problem was coming from where the layer of one view (which had no superview) was being added to another.

看起来这也可能是您自己的情况 - 您创建的工具栏尚未首先添加到超级视图中。我使用的修复是将视图添加为要添加图层的视图的子视图,因此在您的情况下添加工具栏作为myModelView的子视图应该会停止错误。

It looks like this may be the case for yourself also - your toolbar being created has not been added to a superview first. The fix I used was to add the view as a subview of the view that the layer was being added to, so in your case adding the toolbar as a subview of myModelView should stop the error.

这篇关于Swift UIViewReportBrokenSuperviewChain由Layer操作引起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 08:48