4

ストーリーボードに5つのビューがあります。たとえば、あるビューがUIInterfaceOrientationLandscapeRight別のビューになるUIInterfaceOrientationLandscapeLeftか、UIInterfaceOrientationPortraitまたはになるように、各ビューの向きが異なるようにしUIInterfaceOrientationPortraitUpsideDownます。では、このビューの向きをどのように設定するのですか。

使用 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; しましたが、「UIDevice が setOrientation に応答しない可能性があります」という警告が表示されます。私が使用している多くのstackoverflowライターによると

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    //return UIInterfaceOrientationLandscapeLeft;
    return (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
}

これは上記のコードですが、私のプロジェクトでは機能していません。では、画面の向きの適切な手順は何ですか。前もって感謝します。

4

3 に答える 3

2

これを試して

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];

UIDeviceOrientation物理パラメータのため設定できません。デバイスを縦向きで手に持っている場合-プログラムで横向きに設定する方法は?) UIDeviceOrientation意味します-インターフェイスではなく、デバイスの向き。この回答では、向きの違いについて説明しています: https://stackoverflow.com/a/3897243/194544

于 2012-05-22T09:09:20.990 に答える
0

-(BOOL)shouldAutorotateToInterfaceOrientation:各viewControllerに入れて、正しい向きを確認する必要があります。たとえばのみをサポートするviewControllerをプッシュする場合。upsideDown、上下逆に表示されます。

ノート:

  • タブバー環境の場合、動作は異なります。その場合はお尋ねください。
  • rootViewController について話している場合、アプリは最初の viewController (Info.plist) に対応するように設定する必要があります。
于 2012-05-22T09:12:58.570 に答える
0

UIDevice の方向プロパティは読み取り専用です。

を使用[UIViewController attemptRotationToDeviceOrientation];して、すべてのビュー コントローラーをデバイスの現在の向きに回転させることができます。回転を強制的に設定することはできません。

于 2012-05-22T09:13:46.947 に答える