2011-10-13 58 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];