2012-04-30 22 views
2

と変化していない私は、これらのステートメントで背景画像を設定していiOSの5の出現方法を使用して背景画像を使用しようとしています正しい画像がポートレートとランドスケープに表示されますが、ポートレートに戻っても表示されるようになります。UINavigationBarの背景画像が回転

私はここにサンプルテストアプリケーションを作成しました:何が起こっているかの http://dl.dropbox.com/u/7834263/Appearance%20Test.zip

とスクリーンショット:

normal portrait

normal landscape

incorrect portrait

答えて

6

を私はあなたのコードを変更してみました次の012にそれは私にとってうまくいった。

UIImage *portraitImage = [UIImage imageNamed:@"test_bar_portrait.png"]; 
UIImage *landscapeImage = [UIImage imageNamed:@"test_bar_landscape.png"]; 
[[UINavigationBar appearance] setBackgroundImage:portraitImage forBarMetrics:UIBarMetricsDefault]; 
[[UINavigationBar appearance] setBackgroundImage:landscapeImage forBarMetrics:UIBarMetricsLandscapePhone]; 

self.navigationController.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 

ご確認ください。

+0

はい、それをしません。ありがとう! – TigerCoding

+0

ありがとう、これはトリックです。しかし、私は自分のアプリケーションでAutoLayoutを使っているので、autoresizingMaskを使うのは安全ですか?私が知っているとおり、AutoLayoutを使用するときは、autoresizingMaskは使用しません。私が間違っているなら、私を訂正してください。 – iOSAppDev

+0

Autolayoutは、AutoresizingMasksとともに使用できます。あなたは自動サイズ調整しています。マスクは自動レイアウトに変換されます。 UIViewプロパティを参照してください:translatesAutoresizingMaskIntoConstraints – bandejapaisa

0

スウィフト2.0:

let portraitImage: UIImage = UIImage(named: "Navbar.portrait.png")! 
let landscapeImage: UIImage = UIImage(named: "Navbar.landscape.png")! 
UINavigationBar.appearance().setBackgroundImage(portraitImage, forBarMetrics: .Default) 
UINavigationBar.appearance().setBackgroundImage(landscapeImage, forBarMetrics: .CompactPrompt) 
self.navigationController!.navigationBar.autoresizingMask = .FlexibleTopMargin 
+0

私にとっては、 '.compact'バー・メトリックはランドスケープ・モードでのみ機能します – rafalkitta