更新到Xcode版本9.2(9C40b)后应用程序崩溃

时间:2018-03-14 06:40:13

标签: ios objective-c xcode crash uivisualeffectview

我最近更新了我的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:locate:relativeTo:],/ BuildRoot / Library / People / com.apple.xbs / Source / UIKit / UIKit-3698.34.4 / UIVisualEffectView.m:1558

     

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

更改

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

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