UIScrollView 和约束 [英] UIScrollView and Constraints

查看:30
本文介绍了UIScrollView 和约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 UIImageView 放在 UIScrollView 的顶部,当我将 UIScrollView 约束到视图控制器的两侧并将 UIImageView 约束到顶部并使 UIImageView 的宽度等于它生成的 UIScrollView 时UIImageView 比 UIScrollView 更宽,比预期的要高得多.知道我做错了什么吗?

I'm trying to place a UIImageView at the top of a UIScrollView and when I constrain the UIScrollView to the sides of the View Controller and constrain the UIImageView to the top and make the width of the UIImageView equal to the UIScrollView it makes the UIImageView way wider than the UIScrollView, and much taller than expected. Any idea what I'm doing wrong?

故事板:

预览:

推荐答案

检查以下约束是否添加到您的视图中:

  1. 转到故事板 -> 选择您的视图
  2. 现在在右下角,您可以看到用于添加约束的小按钮
  3. 选择固定"按钮
  4. 并标记所有边的所有 4 个约束
  5. 将所有 4 个约束添加到您的视图中

编辑

我已经按照您的描述创建了一个演示.

EDIT

I have created one demo as you described.

UIScrollViewUIImageView 设置所有约束并完美运行.

Set all constraints for UIScrollView and UIImageView and works perfectly.

以下是供您参考的图片.

Below are reference images for you.

Step - 1 : 在 storyboard 中选择 UIView -> Editor -> Resolve layout issues

Step - 1 : In storyboard Select UIView -> Editor -> Resolve layout issues

Step - 2 : 重复同样的操作来添加约束

Step - 3 : 选择 UIScrollView 并从右下角添加约束

Step - 3 : Select UIScrollView and add constraint from right-bottom corner

Step - 4 : 选择 UIImageView 并为其添加约束.

Step - 4 : Select UIImageView and add constraint for it.

这篇关于UIScrollView 和约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆