navigationBar背景图像在横向模式下的iOS 5上的图像
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];
我的图片名称如下:
- 头 - 风景〜iphone.png
- [email protected]~iphone.png
- 头 - 风景〜ipad.png
- header〜iphone.png
- [email protected]~iphone.png
- header〜ipad
编辑:导航栏上的问题的截图:
- iPhone画像: http://imageshack.us/photo/my-images/200/iphoneportrait.png/
- iPhone景观: http://imageshack.us/photo/my-images/193/iphonelandscape.png/
- iPad的肖像: http://imageshack.us/photo/my-images/62/ipadportrait.png/
- iPad的景观: http://imageshack.us/photo/my-images/200/ipadlandscape.png/
任何人有这个问题吗? 即时通信开放就如何解决这个想法,TKZ
我认为你需要做这样的事情:
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)];
}
是否追加〜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];
}
}
但对于风景模式,它使用的人像图像和重复的最后一个像素列完成缺失部分,所以没有好你的问题虽然这可能对其他读者有用。
我无法管理在旋转的iPad上工作的外观方法。即使导航栏的框架正确调整大小,图形也不会更改。最后,我迷上了我所有控制器的viewWillAppear:animated
和willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
方法,只需在iPad上用正确的版本调用setBackgroundImage:
即可。丑陋,但工作。
这可能是一个值得向苹果报告的bug。定义的名称本身也令人困惑,UIBarMetricsLandscapePhone
在iPad上没有意义,您的默认应用程序定位可能是横向的!
只需使用此代码:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"ipad-menubar.png" ] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)] forBarMetrics:UIBarMetricsDefault];
你期待的ipad〜在iPad上,而不是被加载?我以前没有见过这个约定。你有一些自动为你做的代码吗? – Travis
是的,我希望在该设备上加载〜ipad的文件名。我在应用程序的其他图像上使用这种名称,并正确加载。无论如何,我尝试了所有文件的各种类型的文件名,但对于navBar,这个问题仍然存在:\ – iruleonu