iOS アプリで特定の向きのみを許可する方法を明確にする方法を探しています。私は知ってUISupportedInterfaceOrientations
いshouldAutorotateToInterfaceOrientation
ますが、それらの用途と正確にどのように組み合わせるかについて少し混乱しています.
横向きのみを許可するように使用しようとしUISupportedInterfaceOrientations
ましたが、調査して最初の向きに影響することを読むまで、影響はないように見えました。これをテストすると、私のアプリは横向きでしか開かないように見えますが、画面が縦向きの場合はすばやく回転します。
shouldAutorotateToInterfaceOrientation
たとえば、次のように、許可されている向きを制限するために使用できることを知っています。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
ただし、オンラインでいくつかの読書をしているときに、私が読んだshouldAutorotateToInterfaceOrientation
ものはiOS6の時点で非推奨です。
基本的に私の質問は次のとおりです。
- iOS の複数のバージョンで画面の向きを制限するための正しいアプローチは何ですか?
UISupportedInterfaceOrientations
初期方向を制限するのは の唯一の使用ですか?
編集:
受け入れられた回答を拡張するにはshouldAutorotate
、iOS6 で動作します。ロジックを既に実装している場合、および/または以前のバージョンの iOS をサポートしたい場合の簡単な修正として、shouldAutorotateToInterfaceOrientation
次の操作を実行できます。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (BOOL)shouldAutorotate {
return [self shouldAutorotateToInterfaceOrientation:self.interfaceOrientation];
}