2012-04-08 13 views
0

Ich entwickle und iOS-App mit beiden Positionen, Landschaft und Portrait.Stellen Sie Landschaftsbild auf uinavegationBar mit iOS5

Mit iOS5 möchte ich ein Hintergrundbild auf eine benutzerdefinierte UINavegationBar festlegen. Ich

verwendet, dass:

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]; 
} 

ich diesen Code auf der viewDiLoad Methode schreiben, und es funktioniert für Portrait in Ordnung, aber das gleiche Bild für Landscape-Modus verwenden.

Bitte, hilf mir und thaaanks.

Antwort

1

das Hintergrundbild bedingt wie folgt fest:

- (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]; 
    } 
} 

Hoffe, es hilft.

+0

UIBarMetricsLandscapePhone funktioniert nicht. Ihre Antwort funktioniert, wenn ich immer "forBarMetrics: UIBarMetricsDefault" verwende. – ValentiGoClimb