Background:
I have an iPhone application for which I want the launch image to be exactly the same as the background image for the main screen - so that upon loading the "launch image" is shown, then when the apps loads the main screen the background image will be the same, and perfectly line up so there is no change in background perceived
in the main screen viewDidLoad I load the same image into a UIImageView that takes up the entire window
Issue:
- what I get is there is a vertical offset, so there is a noticeable change during the transition
- it appears the issue main be in the vertical alignment for the launch image, in that it appears the top of the launch image starts higher than the bottom of that "carrier - time - battery" bar - it seems this launch image may be开发者_如何学C positioned for it's tops to be from the top of this
- whereas the top of the background image for the main screen (once it loads) is from the bottom point of the "carrier - time - battery" bar
QUESTION: Why is there an offset? How best to fix this?
thanks
There is no need to use two different images for your start up image & background image.
Just set your background imageView's contentMode
to UIViewContentModeBottom
will fix this problem.
for example:
backgroundImageView.contentMode = UIViewContentModeBottom;
The Default.png has to be 320x480(640x960@2x) your view after the startup is only 320x460(640x920@2x) because of the Statusbar.
Try to use 2 different Backgroundimages 320x480 for the startup(top 20px can be blank) and 320x460(640x920@2x) for your app.
This solution works for standard and retina on iPhone and iPad in Portrait or Landscape with or without the Tab Bar. This is necessary because the iPhone Launch Image overlaps the status bar, but the iPad one does not. Source: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[self.backgroundImage setImage:[UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]]];
else
[self.backgroundImage setImage:[UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Default-Portrait" ofType:@"png"]]];
} else {
[self.backgroundImage setImage:[UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Default-Landscape" ofType:@"png"]]];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
self.backgroundImage.transform = CGAffineTransformMakeTranslation(0, -20);
else
self.backgroundImage.transform = CGAffineTransformIdentity;
}
Images used are:
- Default~iphone.png
- Default@2x~iphone.png
- Default-Portrait~ipad.png
- Default-Portrait@2x~ipad.png
- Default-Landscape~iphone.png
- Default-Landscape~ipad.png
- Default-Landscape@2x~iphone.png
- Default-Landscape@2x~ipad.png
In Interface Builder put your background image in like this:
精彩评论