2

iOS アプリで特定の向きのみを許可する方法を明確にする方法を探しています。私は知ってUISupportedInterfaceOrientationsshouldAutorotateToInterfaceOrientationますが、それらの用途と正確にどのように組み合わせるかについて少し混乱しています.

横向きのみを許可するように使用しようとしUISupportedInterfaceOrientationsましたが、調査して最初の向きに影響することを読むまで、影響はないように見えました。これをテストすると、私のアプリは横向きでしか開かないように見えますが、画面が縦向きの場合はすばやく回転します。

shouldAutorotateToInterfaceOrientationたとえば、次のように、許可されている向きを制限するために使用できることを知っています。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
           (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

ただし、オンラインでいくつかの読書をしているときに、私が読んだshouldAutorotateToInterfaceOrientationものはiOS6の時点で非推奨です。

基本的に私の質問は次のとおりです。

  1. iOS の複数のバージョンで画面の向きを制限するための正しいアプローチは何ですか?
  2. UISupportedInterfaceOrientations初期方向を制限するのは の唯一の使用ですか?

編集:

受け入れられた回答を拡張するにはshouldAutorotate、iOS6 で動作します。ロジックを既に実装している場合、および/または以前のバージョンの iOS をサポートしたい場合の簡単な修正として、shouldAutorotateToInterfaceOrientation次の操作を実行できます。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
           (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (BOOL)shouldAutorotate {
    return [self shouldAutorotateToInterfaceOrientation:self.interfaceOrientation];
}
4

2 に答える 2

3

代わりに回転に使用する必要がある方法shouldAutorotateToInterfaceOrientationは、shouldAutorotate

ViewControllers の AppleDoc によると、回転を処理します。

iOS 6 では、アプリは、アプリの Info.plist ファイルで定義されたインターフェイスの向きをサポートします。View Controller は supportedInterfaceOrientations メソッドをオーバーライドして、サポートされている向きのリストを制限できます。通常、システムは、ウィンドウのルート ビュー コントローラー、または画面全体に表示されるビュー コントローラーでのみ、このメソッドを呼び出します。子View Controllerは、親View Controllerによって提供されたウィンドウの一部を使用し、どの回転がサポートされているかについての決定に直接参加しなくなりました。アプリの方向マスクとビュー コントローラーの方向マスクの交点は、ビュー コントローラーを回転できる方向を決定するために使用されます。

特定の向きで全画面表示することを目的としたView ControllerのpreferredInterfaceOrientationForPresentationをオーバーライドできます。

shouldAutorotateToInterfaceOrientationデバイスのローテーションへの応答を処理するいくつかのメソッドと同様に、このメソッドは非推奨です。

複数のバージョンの iOS のサポート方法について、Apple は次のように述べています。

互換性のために、まだ shouldAutorotateToInterfaceOrientation: メソッドを実装しているビュー コントローラーは、新しい自動回転動作を取得しません。(つまり、アプリ、アプリ デリゲート、または Info.plist ファイルを使用して、サポートされている向きを決定する方法にフォールバックしません。)代わりに、 shouldAutorotateToInterfaceOrientation: メソッドを使用して、 supportedInterfaceOrientations メソッドによって返される情報を合成します。 .

リリースノートより抜粋

于 2012-11-30T13:38:05.090 に答える