0

横向きモードのみのアプリを作成していますが、デバイスを回転させると、アプリがその向きに自動回転することがわかりました。プロジェクトの概要で「Landscape Left」のみが必要であることを指定し、次に各View Controllerに配置しました

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

右または左に回転をクリックすると、アプリは横向きで起動しますが、シミュレーターは縦向きになりますが、アプリも自動回転します。デバイスを回転させてもアプリを横向きに保つにはどうすればよいですか?

4

3 に答える 3

1

あなたがしたことに加えて、あなたのshouldAutorotateToInterfaceOrientation関数の代わりに、以下を使用してください

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
于 2012-06-14T18:35:15.483 に答える
0

あなたはそれが何のためにあるのか誤解していると思いますshouldAutorotateToInterfaceOrientation:「どの方向をサポートしますか?」と尋ねているのではありません。「このインターフェイスの向きをサポートしていますか?」尋ねられます。。したがって、答えはまたはのいずれかである必要があります。YESNO

向きを変えることを決定する前に毎回これを尋ねるので、あなたは考えを変えて、時にはそれをサポートすることができますが、そうでない場合もあります(本当に必要な場合)。

たとえば、すべての方向をサポートするには:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

...横向きのみをサポートするには:

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

...横向きのみをサポートするには(必要に応じて):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return(interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
于 2012-06-14T18:47:05.417 に答える
-1

info.plist で、UISupportedInterfaceOrientations以下に示すようにのキーを設定する必要があります。

ここに画像の説明を入力

shouldAutorotateToInterfaceOrientation:この制限は、メソッドに加えて、横向きモードでのみ実行するように私のアプリです。Landscape Left/Right をサポートしている場合。メソッドは次のようになります。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return  (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
于 2012-06-14T18:33:57.727 に答える