更新:这似乎与自动布局无关。即使我禁用自动布局,我仍然会得到相同的结果:(
我在滚动视图中添加了一系列UIImageView
,并在花了数小时试图诊断之后
问题,我得出结论,它必须是一个约束问题,推动我的UIImage
向下。请参阅附图:
正如您所看到的那样UIImage
被按下,因为我已将UIScrollView
背景标记为红色。我还附上了UIScrollView
的约束图片:
以下是我的滚动视图的属性:
如何在UIImageView
上设置约束,使其以UIScrollView
水平居中?我使用以下代码用图像填充UIScrollView
。
for (UIView *v in self.scrollview.subviews)
{
[v removeFromSuperview];
}
CGRect workingFrame = self.scrollview.frame;
workingFrame.origin.x = 0;
for(NSDictionary *dict in info)
{
UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
MyManager * myManager = [MyManager sharedInstance];
[myManager.assets addObject:imageview];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.scrollview addSubview:imageview];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
}
[self.scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
答案 0 :(得分:0)
workingFrame.origin.y = 0;修好了