2012-03-20 10 views
1

私はいくつかの調査をしましたが、私のnavigationControllerのrootViewControllerを起動時に正しいものにする答えが見つからないようです。私の元の質問はここにあった:launch orientation of iPad is incorrect for landscape orientation (upside down)UIViewControllerの向きを強制的に

私のinfo.plistでは、両方向の向きをサポートするように設定しました。私のrootViewControllerを次のように変更した場合:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// return UIInterfaceOrientationIsLandscape(interfaceOrientation); // original that does not work 
    return YES; 
} 

私のアプリは正しい向きで始まります。しかし、私はポートレートモードをサポートしたくありません。私は風景モードをサポートしたいだけです。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     UIDeviceOrientation orientation = UIInterfaceOrientationLandscapeLeft; 
     [UIApplication sharedApplication].statusBarOrientation = orientation; 
    } 
    else { 

    } 

をしかし、これはポートレートモードに回転させられるからアプリを防ぐことはできません:私はオリエンテーションを強制し、このような何かを行うことによって、ポートレートモードに切り替えられることがないようにと考えていました。方向を強制することは可能ですか?スタートアップの向きが正しいようにするために何か必要なことはありますか(ランドスケープモードのみ)?ありがとう!

答えて

1

サンプルプロジェクトを作成しました。サポートされているインターフェイスの向き(iPad)をLandscape LeftとLandscape Right(info.plist)に設定しました。

私はその後使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
をし、それが正常に動作します。私はそれをどのように回転させても構わない。

すべての向きに対してYESを返す可能性のある他のビューコントローラが表示されていますか?これはそれを混乱させる可能性があります。

+0

私はAppDelegateでUINavigationControllerを使用しているので、それはまったく問題なのでしょうか? – Crystal

+0

UINavigationControllerで使用する他のすべてのView Controllerが同じshouldAutorotateポリシーを持っている限り、問題はありません。 – bandejapaisa

+0

ええ、私はまだ問題が発生しています。私のアプリケーションが最初に起動するとき、私はモーダルフォームと要件ごとにUIAlertViewを表示する必要があります。基本的には、tvcは私のviewControllerです。私はモーダルで表示します: 'tvc.modalPresentationStyle = UIModalPresentationFormSheet; tvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal; [self presentModalViewController:tvc animated:YES]; '。このViewControllerはUIInterfaceOrientationIsLandscape(interfaceOrientation)を返すようにshouldAutoRotateを設定しています。このビューコントローラは、それを正しく起動させることができませんでしたか? – Crystal

関連する問題