1

UINavigationBariOS5 に切り替えて、次のコード スニペットを使用してカスタム スタイルを利用したいと考えました。

if ([navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:
                                                                         forBarMetrics:)]) {
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBar.png"] 
                                           forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBarLandscape.png"] 
                                           forBarMetrics:UIBarMetricsLandscapePhone];
    }

これは非常にうまく機能しますが、カスタム イメージの角が丸くなっているため (添付のイメージを参照)、次のような問題が発生します。

ポートレートモードから始めると、きれいに見えます。

縦(ノーマル)

ランドスケープモードへの変更も見栄えがします。

横向き(通常)

ただし、ポートレート モードに戻しても、画像がNavigationBar.pngに変更されないように見えるため、右上に丸みを帯びた角はありません。

縦長(右上の角を丸くしない)

この問題を解決する方法についてアドバイスをいただければ幸いです。

// 編集

私のviewControllerに次のコードを追加すると、この「バグ」は取り除かれますが、これは正しい解決策ではありません!?!

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation 
                                            duration:duration];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBar.png"] 
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBarLandscape.png"] 
                                                  forBarMetrics:UIBarMetricsLandscapePhone];
}
4

1 に答える 1

0

iOS6 ではデフォルトで角が丸くなっているため、この問題はすぐに解消されます。

于 2012-09-18T11:37:13.800 に答える