简体   繁体   中英

UIScrollView and Constraints

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM