Markus
Markus

Reputation: 33

Rotate UIImageView and make aspect ratio update properly

I have a UIScrollview, inside this scrollview I have a container UIView that contains an UIImageView (scaleToAspect). I use the scrollview to zoom/pan the container-UIView. It works. The user should also be able to rotate the image, i do this by performing an CGAffineTransform on the ImageView. When transforming the ImageView the bounds are not updated so if starting out in Portrait the image fills up aspect correct to the width with margins on bottom and top. After translation to landscape i get the exact same margins on the sides instead (where there should be no margins” so the image dont fill the full width. How to manage this correctly?

Before rotation After rotation

Upvotes: 0

Views: 876

Answers (1)

Markus
Markus

Reputation: 33

The solution was to make bounds of ImageView equal to the frame of the container-UIView that is a direct child to the ScrollView.

imageView.bounds = imageView.superview!.frame

Upvotes: 1

Related Questions