Autoresizing problem


I had this problem with autoresizing but I will post the solution also as others may get interested or tell me if I was doing smth wrong.

Even though I had set my autoresizing properties like this:

When rotated the image looked like this (this is not similar to figure 8.8 as in the book):

However, after slightly changing the position of the image on the view like this:

the autoresizing now seems to work as needed.


If you’re using the struts and springs autosizing method (as described in the book), this is happening because in the first run, the space between the UIImage and the main view’s border (which in this case, is the screen top and bottom) is too great. In other words, your Y-offset is too much (or your image Height is too little, which has the same effect). The top and bottom struts means that the image will resize to maintain the same “margin” (if you will) with the top and bottom. So, if that margin is too big, the picture could be too small - or even disappear entirely.

To put it to an example, assume you have a 1’’ margin on both the top and bottom, with the photo centered. If you enable the top and bottom struts, those 1’’ margins MUST be maintained, even when rotated and/or resized. So, in landscape view, those 2 inches of margin will force the image to be very, very small.

In your second example, you effectively fixed the issue by increasing the Height of the UIImage. This reduces the “margin”.

To wit, this is one of the reasons why the Xcode 4.5/iOS 6 “Constraints” method is much more powerful than the old “struts and springs” autoresizing.