我正在制作一个应用程序,其中我在 UINavigationBar 背景中使用徽标。当 iPad 从纵向模式变为横向模式时,该徽标会拉伸并且看起来很难看。我为纵向和横向模式制作了两个不同的背景图像,然后使用以下代码对其进行更改:
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
NSLog(@"orientation is UIInterfaceOrientationPortrait");
UINavigationBar *navBar = [[self navigationController] navigationBar];
[navBar setBackgroundImage:[UIImage imageNamed:@"portrait_bg.png"] forBarMetrics:UIBarMetricsDefault];
}else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
NSLog(@"orientation is UIInterfaceOrientationLandscapeLeft");
UINavigationBar *navBar = [[self navigationController] navigationBar];
[navBar setBackgroundImage:[UIImage imageNamed:@"landscape_bg.png"] forBarMetrics:UIBarMetricsDefault];
}else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
NSLog(@"orientation is UIInterfaceOrientationLandscapeRight");
UINavigationBar *navBar = [[self navigationController] navigationBar];
[navBar setBackgroundImage:[UIImage imageNamed:@"landscape_bg.png"] forBarMetrics:UIBarMetricsDefault];
}else{
NSLog(@"orientation is UIInterfaceOrientationPortrait 2");
UINavigationBar *navBar = [[self navigationController] navigationBar];
[navBar setBackgroundImage:[UIImage imageNamed:@"portrait_bg.png"] forBarMetrics:UIBarMetricsDefault];
}
}
但这不起作用。它没有改变任何东西。知道我该怎么做吗?提前致谢。