IOS Aspect Fill Image Resizing with content matching left / top

I am developing a universal application for iOS-7. This specific question is specific to iPad only. I want to put the image as the background of the root representation of the view controller, that is, the image should fill the entire screen. 1x image has a size: 768x1024. This works for portrait orientations, since the iPad’s non-mesh resolution is also 768x1024 in portrait. However, the image is not suitable in the landscape. I tried to use ScaleToFit, but since the aspect ratio of the image was not preserved, I can not use ScaleToFit (their images in the image look odd if they are not scaled proportionally along both axes). Resizing AspectFill seems the most suitable for my needs, but this is a small problem. As defined in the Apple documentation "Content Modified,to completely fill the border rectangle while preserving the aspect of the content.Content is centered on an axis that exceeds it. ". I don’t want the content to be centered on the axis in which it exceeds, I want it to be aligned with the top / left edge.

So basically I want two things:

  • Filling aspect
  • Content remains aligned left / top.

Is it possible to achieve this. Any piece of code will be great.

thank

+4
source share
2 answers

You will have to subclass the View Controller view and manually scale and align.

Look at the code snippets in the IT answer.

Adjust the image of ViewXOrigin and imageViewYOrigin to align as you want.

+1
source

, - , . viewAnimateToOrientation: , UIKit.

0

Source: https://habr.com/ru/post/1540742/


All Articles