Scale image to fit screen on iPhone rotation

前端 未结 2 2068
别那么骄傲
别那么骄傲 2021-01-02 12:45

I have a UIScrollView containing an UIImageView and I have some trouble to get the correct behavior when the iPhone rotates.

Goal: I am trying to o

2条回答
  •  迷失自我
    2021-01-02 12:51

    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;
    

提交回复
热议问题