为什么iPhone在启动时启动图像与主屏幕背景图像不匹配?

问题描述:

背景:为什么iPhone在启动时启动图像与主屏幕背景图像不匹配?

  • 我有,我想推出图像完全相同作为主屏幕的背景图像的iPhone应用程序 - 这样在加载“启动图像”所示,然后当应用程序加载主屏幕的背景图像将是相同的,并完美地排队所以在背景在主画面viewDidLoad中感知

  • 我相同的图像加载到一个UIImageView,占用了整个无变化窗口

问题:

  • 我所得到的是有一个垂直偏移,所以在转换过程中一个显着的变化
  • 它出现的问题主要是在为推出图像的垂直对齐,在它看起来发射图像的顶部开始高于该“运营商时间 - 电池”栏的底部 - 看起来这个发射图像可能定位于顶部,从这个顶部到顶部,而顶部主屏幕的背景图像(一旦加载完成)就是从“载体 - 时间 - 电池”栏的底部开始的

问题:为什么会有偏移?如何最好地解决这个问题?

感谢

+0

而且,这条被称为*“状态栏” * – EmptyStack

有没有必要使用两个不同的图像为您的启动图像&背景图像。

只要设置你的背景图像的contentModeUIViewContentModeBottom将解决这个问题。

例如:

backgroundImageView.contentMode = UIViewContentModeBottom;

+0

谢谢 - 不完全知道如何工作的,但它似乎工作... – Greg

+0

哦 - 我只是注意到这种方法,当我进入风景模式的设备,然后图像不再方面适合所有的屏幕(所以有垂直边缘酒吧目前没有充满图像)...如何改变方法也允许这个? – Greg

+0

由于肖像模式(320 * 460)和风景模式(480 * 300)之间的尺寸不同,因此您必须为两种尺寸制作两幅背景图像。让UIImageView自动拉伸图像会导致您第一次尝试解决的问题,并且还会使图像看起来模糊。 – xuzhe

的为Default.png必须为320x480像素(640×960 @ 2X)视图后的启动仅仅是320x460(640x920 @ 2X),因为状态栏的。

尝试为您的应用使用2个不同的Backgroundimages 320x480用于启动(顶部20px可以为空)和320x460(640x920 @ 2X)。

该解决方案适用于标准和视网膜iPhone和iPad在纵向或横向带或不带标签栏。这是必要的,因为iPhone启动图像与状态栏重叠,但是iPad没有。来源:采用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; 
} 

图像是:

在Interface Builder把你的背景图像像这样的:

enter image description here