2012-04-08 6 views
0

私は、両方の位置、風景、およびポートレートでiOSアプリケーションを開発しています。風景画像をiOS5でuinavegationBarに設定

iOS5を使用して、背景画像をカスタムUINavegationBarに設定したいと思います。

私はそれを使用:

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

私はviewDiLoad方法でこのコードを書き、それは肖像画のために[OK]を動作しますが、ランドスケープモードで同じ画像を使用しています。

私とthaaanksを助けてください。次のように条件付きで背景画像を設定し

答えて

1

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

はそれがお役に立てば幸いです。

+0

UIBarMetricsLandscapePhoneは機能しません。私が常に "forBarMetrics:UIBarMetricsDefault"を使用すると、あなたの答えが働きます。 – ValentiGoClimb

関連する問題