简体   繁体   中英

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

解决方案是使ImageView的边界等于容器UIView的框架,该框架是ScrollView的直接子级。

imageView.bounds = imageView.superview!.frame

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