我有一个 UIScrollView 来显示 UIImageViews。 ImageViews 在运行时根据用户先前保存的图像数量以编程方式插入。我收到以下错误:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one
you don't want. Try this: (1) look at each constraint and try to
figure out which you don't expect; (2) find the code that added the
unwanted constraint or constraints and fix it. (Note: If you're seeing
NSAutoresizingMaskLayoutConstraints that you don't understand, refer
to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
"<NSLayoutConstraint:0x17029cd90 H:[UIView:0x15cd31e70]-(0)-| (Names: '|':UIScrollView:0x15cd326b0 )>",
"<NSLayoutConstraint:0x17029d060 UIScrollView:0x15cd326b0.trailingMargin == UIView:0x15cd31e70.trailing>"
我做了基本的自动布局, ScrollView 在 0 点处固定在所有四个边上。然后我添加一个 contentView 作为 UIScrollView 的 subview (普通 UIView),它也固定在 0 点的所有四个边上。
编辑 Storyboard 约束图像
我在代码中给 contentView 一个宽度,如下所示:
CGSize pagesScrollViewSize = self.scrollView.frame.size;
NSDictionary *views = @{ @"contentView" : self.contentView};
NSDictionary *metrics = @{ @"width" : @(pagesScrollViewSize.width * self.mutableArray.count) };
NSArray *constraints;
constraints = [NSLayoutConstraint constraintsWithVisualFormat"H:|-[contentView(width)]-|" options:0 metrics:metrics views:views];
[self.scrollView addConstraints:constraints];
[self loadVisiblePages];
UIImageViews 的添加方式是这样的,UIImageViews 的添加是根据发生到 ViewController 的 segue 时设置的页数来添加的。
-(void)loadVisiblePages{
CGRect frame = self.scrollView.bounds;
frame.origin.x = frame.size.width * self.page;
frame.origin.y = 0.0f;
ImageForArchiving *newImageObject = (ImageForArchiving*)self.mutableArray
|