UIScrollView and Constraints

ぐ巨炮叔叔 提交于 2019-12-17 05:13:28

问题


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:


回答1:


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.



来源:https://stackoverflow.com/questions/26133144/uiscrollview-and-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!