Reputation: 105
I have recently updated my Xcode, after updating the Xcode I am facing a crash. Here the crash happening
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];
Where _bgView
is UIView
and _menuTable
is UITableView
;
the logs stating the following error message.
Assertion failure in -[UIVisualEffectView _addSubview:positioned:relativeTo:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.34.4/UIVisualEffectView.m:1558
Terminating app due to uncaught exception NSInternalInconsistencyException', reason: '; layer = ; contentOffset: {0, 0}; contentSize: {281.25, 72}; adjustedContentInset: {0, 0, 0, 0}> has been added as a subview to ; layer = >. Do not add subviews directly to the visual effect view itself, instead add them to the -contentView.
Before updating he Xcode it is working fine.
Upvotes: 0
Views: 601
Reputation: 1196
This error message is caused by trying to add a subview to the UIVisualEffectView
.
Change
UIVisualEffectView *vsview = [[UIVisualEffectView alloc]initWithEffect:blur];
[vsview addSubview:newView];
to
UIVisualEffectView *vsview = [[UIVisualEffectView alloc]initWithEffect:blur];
[vsview.contentView addSubview:newView];
Upvotes: 0
Reputation: 13
Make sure that you are not adding anything as child to the visual effect view
Upvotes: 0