使用iOS5将横向图像设置为uinavegationBar

使用iOS5将横向图像设置为uinavegationBar,ios5,landscape-portrait,Ios5,Landscape Portrait,我正在开发和iOS应用程序,包括位置、横向和纵向 使用iOS5,我想将背景图像设置为自定义UINavigationBar 我用的是: if([self.navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) { [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsPort.png"] forBarMetrics

我正在开发和iOS应用程序,包括位置、横向和纵向

使用iOS5,我想将背景图像设置为自定义UINavigationBar

我用的是:

if([self.navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {

    [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsPort.png"]  forBarMetrics:UIBarMetricsDefault];
    [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsLand.png"]  forBarMetrics:UIBarMetricsLandscapePhone];
}
我用viewdload方法编写了这段代码,它对纵向模式工作正常,但对横向模式使用相同的图像


请帮助我和thaaanks。

按如下条件设置背景图像:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

  if (UIDeviceOrientationIsLandscape(toInterfaceOrientation)) {
        [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsLand.png"]  forBarMetrics:UIBarMetricsLandscapePhone];
    }
    else if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) {
        [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsPort.png"]  forBarMetrics:UIBarMetricsDefault];
    }
}

希望有帮助。

UIBarMetricsLandscape电话不工作。如果我总是使用“forBarMetrics:UIBarMetricsDefault”,您的答案就行了。