UIImageView 使其他视图不一致

UIImageView making other Views inconsistent

我设计了一个ViewController,有一个ImageView,3个Label-TextField组合,一个Label和一个Toolbar在底部看法。所有这些视图元素都在 Stack View 内。设计如下:

ImageViewcontentMode 属性 在 Attributes Inspector 中设置为 Aspect Fit

现在当我 运行 应用程序和 select 不同尺寸的照片时, ImageView 似乎不同时间不一致。喜欢:

The teal color background the ImageView is set to distinguish the difference between the ImageView and the original Background.

没关系。但是当我选择一张大尺寸照片时,它似乎不一致,因为 ImageView 与下面的 Toolbar 重叠,这次 Camera 按钮不再可点击。这是图片:

当我选择另一张照片时,设计变得更加糟糕。视图在不同的时间以不同的方式显示。截图为: and

Now what to do? I haven't done any of these design from the code side, all from the Interface Builder.

Any help will be appreciable.

我在 Attributes InspectorDrawing 部分中有这些选项:

这是我的 Stack View 的属性:

首先,确保您已在属性检查器中选中 Clip To Bounds 属性 或 UIImageView

其次,设置您的约束和/或 Stack ViewDistribution 属性,使您的所有视图都在可用高度内。

这是一个示例:https://www.dropbox.com/s/5a7r0oz1v8vclgz/AspectFitImageView.zip?dl=0

嗯,看来一切都很好。只需在您的工具栏中添加高度限制。问题将得到解决。

找了很多方法,终于解决了这个问题。设置 content hugging priority(不想增长)和 content compression resistance priority(不想收缩)有很大帮助。基本上我需要垂直调整元素。因此调整每个元素的垂直优先级解决了我的问题。因为我必须不时更改 ImageView 的大小,所以我将其设为垂直 huggingcompression要低于其他元素的Stack View。其他优先级保持默认。

为了使情况形象化,这里附上图片。这里使用颜色组合来区分 Stack View. 元素

Hope this helps.