UINavigationBar
iOS5 に切り替えて、次のコード スニペットを使用してカスタム スタイルを利用したいと考えました。
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];
}