【发布时间】:2018-08-16 11:00:02
【问题描述】:
我是 iOS 新手。这是我的代码导致错误。
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
}
}
异常发生在 Anchor 的东西上。它说..
由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法使用锚激活约束,因为它们没有共同的祖先。约束或其锚点是否引用不同视图层次结构中的项目?这是非法的。'
【问题讨论】: