Scale image to fit screen on iPhone rotation

℡╲_俬逩灬. 提交于 2019-11-30 13:49:22

Try this:

scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                           UIViewAutoresizingFlexibleHeight);    
imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                           UIViewAutoresizingFlexibleHeight);

imageView.contentMode = UIViewContentModeAspectFit; // You could also try UIViewContentModeCenter

I'm not sure if the imageView will get automatically resized within a UIScrollView, so if the autoresizing doesn't work, you could try setting the frame yourself on rotate to equal the size of the scrollview.

I had a similar situation, a very simple scrollView with 3 imageViews ('previous', 'current', and 'next') to display a series of photos.

The photos were all sized for the iPad, but a mix of landscape and portrait orientations. I wanted them to fit into the screen, (i.e. letterboxed if necessary), with aspect ratio retained. I found I only needed to do this to the 3 imageViews for it to work:

imageView.contentMode = UIViewContentModeScaleAspectFit;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!