简体   繁体   English

旋转UIImageView并使纵横比正确更新

[英]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). 我有一个UIScrollview,在这个scrollview中,我有一个包含UIImageView(scaleToAspect)的容器UIView。 I use the scrollview to zoom/pan the container-UIView. 我使用scrollview来缩放/平移UIUI容器。 It works. 有用。 The user should also be able to rotate the image, i do this by performing an CGAffineTransform on the ImageView. 用户还应该能够旋转图像,我可以通过在ImageView上执行CGAffineTransform来实现。 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. 转换ImageView时,边界不会更新,因此,如果从“纵向”开始,图像将填充正确的宽高比,其宽度在底部和顶部具有边距。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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