I'm new to iOS. Here is my code causing the error.
FSImageView *imageView = [_imageViews objectAtIndex:(NSUInteger) page];
if ((NSNull *) imageView == [NSNull null]) {
imageView = [self dequeueImageView];
if (imageView != nil) {
[_imageViews exchangeObjectAtIndex:(NSUInteger) imageView.tag withObjectAtIndex:(NSUInteger) page];
imageView = [_imageViews objectAtIndex:(NSUInteger) page];
}
}
if (imageView == nil || (NSNull *) imageView == [NSNull null]) {
imageView = [[FSImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, _scrollView.bounds.size.width, _scrollView.bounds.size.height)];
UIColor *backgroundColor = barsHidden ? _backgroundColorHidden : _backgroundColorVisible;
[imageView changeBackgroundColor:backgroundColor];
[_imageViews replaceObjectAtIndex:(NSUInteger) page withObject:imageView];
}
imageView.useScaleFactor = self.useScaleFactor;
imageView.image = _imageSource[page];
if (imageView.superview == nil) {
[_scrollView addSubview:imageView];
if (@available(iOS 11.0, *)) {
[imageView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor
constant:0.0].active = YES;
[imageView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor
constant:0.0].active = YES;
} else {
// Fallback on earlier versions
}
}
The exception occurs at Anchor stuffs. It says..
Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'