Skip navigation

I was trying to make an iPhone app that performed what I thought was a simple task:  seamlessly transitioning from the default image displayed when the app was opened (Default.png) into a fullscreen UIImageView that showed the exact same image.  Unfortunately I kept running into alignment problems where one image seemed to be displaced by 20 pixels (40 pixels on retina displays), and initially I couldn’t even tell whether it was the default image or ensuing UIImageView image that was offset.  I eventually figured out that it was the UIImageView image that was the problem, but determining why was a bit trickier.I of course knew that the offset was the same size as the status bar, but the odd thing was that the status bar was present on both screens so that didn’t seem like it should be the cause of the issue.  It turns out that the status bar was the cause of the problem, but it’s because of an obscure difference in the way default images are handled.  If the status bar is displayed during your app startup, the default image will always be displayed underneath it (as in starting at the same height on the screen and obscured by the status bar), while the UIImageView image will be displayed immediately below it (as in starting at the height that the status bar ends).  Therefore in my case I had two options:

  1. Create a separate image file for the default image that had a built-in offset of 20 (or 40) pixels.
  2. Hide the status bar at all times in my app.
Since I wanted my app to run on several different types of devices and displays, I didn’t want to have to make a whole new set of image files just for my default image(s) so I went with option 2.  Hiding the status bar immediately fixed my problem and all alignment issues vanished.

Leave a Reply

Your email address will not be published. Required fields are marked *