2011-10-13 57 views
3

Im在這一段時間裏掙扎着,我無法找到任何有相關問題的人。 我的問題是,在iPad上爲橫向模式加載的背景圖像不是正確的(它削弱了圖像的肖像版本)。 在iPhone或iPod上,它的工作方式與其應有的相同。navigationBar背景圖像在橫向模式下的iOS 5上的圖像

使用我的AppDelegate文件中的代碼IM如下:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { 
    // Create resizable images 
    UIImage *gradientImageP = [[UIImage imageNamed:@"header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
    UIImage *gradientImageL = [[UIImage imageNamed:@"header-Landscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
    [[UINavigationBar appearance] setBackgroundImage:gradientImageP 
             forBarMetrics:UIBarMetricsDefault]; 
    [[UINavigationBar appearance] setBackgroundImage:gradientImageL 
             forBarMetrics:UIBarMetricsLandscapePhone]; 
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent]; 
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0 green: 0 blue:0 alpha:1]]; 
} 

的問題是在這條線?

[[UINavigationBar appearance] setBackgroundImage:gradientImageL 
            forBarMetrics:UIBarMetricsLandscapePhone]; 

我的圖片名稱如下:

編輯:導航欄上的問題的截圖:

任何人有這個問題嗎? 即時通信開放就如何解決這個想法,TKZ

+0

你期待的ipad〜在iPad上,而不是被加載?我以前沒有見過這個約定。你有一些自動爲你做的代碼嗎? – Travis

+0

是的,我希望在該設備上加載〜ipad的文件名。我在應用程序的其他圖像上使用這種名稱,並正確加載。無論如何,我嘗試了所有文件的各種類型的文件名,但對於navBar,這個問題仍然存在:\ – iruleonu

回答

0

我認爲你需要做這樣的事情:

UIImage *gradientImageP; 
UIImage *gradientImageL; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
    //use iPhone specific images 
    gradientImageP = [[UIImage imageNamed:@"header~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
    gradientImageL = [[UIImage imageNamed:@"header-Landscape~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    //use iPad specific images 
    gradientImageP = [[UIImage imageNamed:@"header~Landscape~ipad.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

} 
+0

已經嘗試使用(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad),同樣的問題:\ – iruleonu

+0

我被教導認爲,做的工作,可能是因爲我的代碼有問題,但在這種情況下,我認爲問題是這個新班級從iOS 5到「新」 – iruleonu

+0

我只是想到了一些東西......你不需要用於iPad的「風景」圖像...因爲UINavigationBar在iPhone上的橫向和縱向上都是相同的高度。 – Travis

1

是否追加〜iPad的工作,爲肖像模式?

這不適合我。你還必須指定〜iPhone來使其工作?

我有一個單獨的圖像爲iPad工作做

- (void)customizeAppearance { 

    if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) { 

     // Create resizable images for iphone 
     UIImage *navbarImage44 = [[UIImage imageNamed:@"navbar_bg_portrait"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
     UIImage *navbarImage32 = [[UIImage imageNamed:@"navbar_bg_landscape"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

     // Overide for iPad 
     // In theory navbar_bg_landscape~iPad should work 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
      //use iPad specific image extending last pixel for landscape mode 
      navbarImage44 = [[UIImage imageNamed:@"navbar_bg_portrait~iPad"] 
             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 767, 0, 0)]; 
     } 

     // Set the background image for *all* UINavigationBars 
     [[UINavigationBar appearance] setBackgroundImage:navbarImage44 
              forBarMetrics:UIBarMetricsDefault]; 
     // Never called on iPad, used for landscape on iPhone 
     [[UINavigationBar appearance] setBackgroundImage:navbarImage32 
              forBarMetrics:UIBarMetricsLandscapePhone]; 
    } 
} 

但對於風景模式,它使用的人像圖像和重複的最後一個像素列完成缺失部分,所以沒有好你的問題雖然這可能對其他讀者有用。

+0

appendng〜iPhone和〜ipad偉大的iphone版本,但不是在iPad上。 – iruleonu

+0

我測試過你的代碼,如果條件爲iPad,它不適用於肖像版本,繼承人截圖:http://img577.imageshack.us/img577/3118/semnomeq.png正如我所說,它可能是一個模擬器問題? – iruleonu

1

我無法管理在旋轉的iPad上工作的外觀方法。即使導航欄的框架正確調整大小,圖形也不會更改。最後,我迷上了我所有控制器的viewWillAppear:animatedwillAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration方法,只需在iPad上用正確的版本調用setBackgroundImage:即可。醜陋,但工作。

這可能是一個值得向蘋果報告的bug。定義的名稱本身也令人困惑,UIBarMetricsLandscapePhone在iPad上沒有意義,您的默認應用程序定位可能是橫向的!

3

只需使用此代碼:

[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"ipad-menubar.png" ] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)] forBarMetrics:UIBarMetricsDefault];