UIScrollView和约束 [英] UIScrollView and Constraints

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

问题描述

我试图在UIScrollView的顶部放置一个UIImageView,当我将UIScrollView约束到View控制器的两侧,并将UIImageView约束到顶部,并使UIImageView的宽度等于其UIScrollView UIImageView方式比UIScrollView宽,并且比预期高得多。任何想法我做错了什么?



故事板:





预览:



解决方案

检查是否向您的数据视图添加了以下约束:


  1. 转到故事板 - >选择视图

  2. 现在在右下角,您可以看到小按钮添加约束。

  3. 选择固定并标记所有边的所有4个约束

  4. 将全部4个约束添加到视图中



EDIT



我已按照您的说明创建了一个演示。



ImageConstraint演示



设置所有约束UIScrollView UIImageView ,并完美地工作。



以下是您的参考图片。



故事板:


$ b b

>



关注以下步骤



步骤1:在故事板中选择 UIView - >编辑器 - >解决布局问题



p>

步骤-2:重复此操作添加约束





步骤3:选择 UIScrollView 并从右下角添加约束





步骤4:选择 UIImageView 并为其添加约束。




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?

Storyboard:

Preview:

解决方案

Check that following constraints are added to your view:

  1. Go to Storyboard -> Select your view
  2. Now at right-bottom corner you can see small buttons to add constraints
  3. Select "Pin" button
  4. And mark all 4 constraints for all sides
  5. Add all 4 constraints to your view

EDIT

I have created one demo as you described.

ImageConstraint Demo

Set all constraints for UIScrollView and UIImageView and works perfectly.

Below are reference images for you.

Storyboard:

FOLLOW BELOW STEPS

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

Step - 2 : Repeat same to add constraint

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

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

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

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