0

私は、横向きと縦向きの両方の位置でiOSアプリを開発しています。

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メソッドで記述します。ポートレートでは問題なく機能しますが、ランドスケープモードでは同じ画像を使用します。

どうか、私とthaaanksを助けてください。

4

1 に答える 1

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

それが役に立てば幸い。

于 2012-04-08T18:51:49.200 に答える