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):

enter image description here

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:

enter image description here

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

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -