【问题标题】:Application crashes after updating to Xcode Version 9.2 (9C40b)更新到 Xcode 版本 9.2 (9C40b) 后应用程序崩溃
【发布时间】:2018-03-14 06:40:12
【问题描述】:

我最近更新了我的 Xcode,更新 Xcode 后我面临崩溃。 这里发生了崩溃

    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *vsview = [[UIVisualEffectView alloc]initWithEffect:blur];


    _bgView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
    _bgView.alpha = 0;
    _bgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *buttonTap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];

    buttonTap2.cancelsTouchesInView = NO;
    vsview.frame = _bgView.bounds;
    _bgView = vsview;
    [_bgView addGestureRecognizer:buttonTap2];


    _normalImageView = [[UIImageView alloc]initWithFrame:self.bounds];
    _normalImageView.userInteractionEnabled = YES;
    _normalImageView.contentMode = UIViewContentModeScaleAspectFit;
    _normalImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    _normalImageView.layer.shadowRadius = 5.f;
    _normalImageView.layer.shadowOffset = CGSizeMake(-10, -10);



    _pressedImageView  = [[UIImageView alloc]initWithFrame:self.bounds];
    _pressedImageView.contentMode = UIViewContentModeScaleAspectFit;
    _pressedImageView.userInteractionEnabled = YES;


    _normalImageView.image = _normalImage;
    _pressedImageView.image = _pressedImage;


    [_bgView addSubview:_menuTable];

其中_bgViewUIView_menuTableUITableView

说明以下错误消息的日志。

-[UIVisualEffectView 中的断言失败 _addSubview:positioned:relativeTo:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.34.4/UIVisualEffectView.m:1558

由于未捕获的异常 NSInternalInconsistencyException 而终止应用程序',原因:'; 层 = ;内容偏移:{0, 0};内容大小: {281.25, 72}; adjustedContentInset: {0, 0, 0, 0}> 已添加为 子视图;层=>。不要将子视图直接添加到视觉效果视图中 本身,而是将它们添加到 -contentView。

在更新他的 Xcode 之前它工作正常。

【问题讨论】:

  • 你到底在问什么?因为您需要解决的所有问题都在您提供的崩溃描述中。
  • 我尝试添加 [_bgView.contentView addSubview:_menuTable];但如果我试图让 _bgView 有一个背景透明视图并且它没有显示。
  • 好吧,实际上,您在_bgView 上设置alpha = 0 与您编写代码的方式无关,因为您稍后将vsView 分配给该变量,因此之前的所有内容都会被丢弃。有没有办法提供MCVE

标签: ios objective-c xcode crash uivisualeffectview


【解决方案1】:

确保您没有将任何内容作为子项添加到视觉效果视图中

【讨论】:

    【解决方案2】:

    此错误消息是由于尝试将子视图添加到 UIVisualEffectView 引起的。

    改变

    UIVisualEffectView *vsview = [[UIVisualEffectView alloc]initWithEffect:blur];
    [vsview addSubview:newView];
    

    UIVisualEffectView *vsview = [[UIVisualEffectView alloc]initWithEffect:blur];
    [vsview.contentView addSubview:newView];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多