Scale image to fit screen on iPhone rotation

前端 未结 2 2089
别那么骄傲
别那么骄傲 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 13:13

    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.

提交回复
热议问题