2011-08-28 170 views
3

背景:爲什麼iPhone在啓動時啓動圖像與主屏幕背景圖像不匹配?

  • 我有,我想推出圖像完全相同作爲主屏幕的背景圖像的iPhone應用程序 - 這樣在加載「啓動圖像」所示,然後當應用程序加載主屏幕的背景圖像將是相同的,並完美地排隊所以在背景在主畫面viewDidLoad中感知

  • 我相同的圖像加載到一個UIImageView,佔用了整個無變化窗口

問題:

  • 我所得到的是有一個垂直偏移,所以在轉換過程中一個顯着的變化
  • 它出現的問題主要是在爲推出圖像的垂直對齊,在它看起來發射圖像的頂部開始高於該「運營商時間 - 電池」欄的底部 - 看起來這個發射圖像可能定位於頂部,從這個頂部到頂部,而頂部主屏幕的背景圖像(一旦加載完成)就是從「載體 - 時間 - 電池」欄的底部開始的

問題:爲什麼會有偏移?如何最好地解決這個問題?

感謝

+0

而且,這條被稱爲*「狀態欄」 * – EmptyStack

回答

3

有沒有必要使用兩個不同的圖像爲您的啓動圖像&背景圖像。

只要設置你的背景圖像的contentModeUIViewContentModeBottom將解決這個問題。

例如:

backgroundImageView.contentMode = UIViewContentModeBottom;

+0

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

+0

哦 - 我只是注意到這種方法,當我進入風景模式的設備,然後圖像不再方面適合所有的屏幕(所以有垂直邊緣酒吧目前沒有充滿圖像)...如何改變方法也允許這個? – Greg

+0

由於肖像模式(320 * 460)和風景模式(480 * 300)之間的尺寸不同,因此您必須爲兩種尺寸製作兩幅背景圖像。讓UIImageView自動拉伸圖像會導致您第一次嘗試解決的問題,並且還會使圖像看起來模糊。 – xuzhe

1

的爲Default.png必須爲320x480像素(640×960 @ 2X)視圖後的啓動僅僅是320x460(640x920 @ 2X),因爲狀態欄的。

嘗試爲您的應用使用2個不同的Backgroundimages 320x480用於啓動(頂部20px可以爲空)和320x460(640x920 @ 2X)。

0

該解決方案適用於標準和視網膜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