ios - How to scale a UIImage view to a square with Autolayout inside a UIScrollView -
i've been struggling learn autolayout (finally). want have vertically scrolling uiscrollview holds content view. want pin uiimage view top of scrollview , keep image square (scaletofill). want (only want autolayout):
i can't image keep aspect ratio while staying within screen bounds. whenever add aspect ratio constraint imageview grows 600 points (the width of png think), want wide screen.
i think setting constraints uiimageview correctly because if rid of scrollview , drop imageviw directly on view seems want to. trick putting inside scrollview.
this how have set up:
the 4 vertical/horizontal space constraints on scroll view set constant 0.
since size of uiscrollview
depends on content, cannot have size of uiimageview
subview dependent on it.
you have remove aspect ratio constraint of uiimageview
, use fixed width one. can have uiimageview
width dependent on view in uiscrollview
has either fixed width or otherwise unambiguous width.
don't forget use placeholder intrinsic size value in interface builder.
hope helps.
Comments
Post a Comment