2

UINavigationController の上にある 1 つのビュー コントローラーを制限しようとしています。そのために、UINavigationController サブクラスを作成し、2 つのメソッドを実装しました。

- (BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];}

- (NSUInteger)supportedInterfaceOrientations {
return [[self.viewControllers lastObject] supportedInterfaceOrientations];}

UINavigationController (ルート ビュー コントローラー) の上にある最初のビュー コントローラーをポートレート モードにし、ルート ビュー コントローラーからプッシュする次のビュー コントローラーをランドスケープ モード (のみ) にする必要があります。

したがって、両方のビュー コントローラーでこれら 2 つのメソッドをオーバーライドしています。ルートビューコントローラーで

- (BOOL)shouldAutorotate {
return NO;}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;}

次のView Controllerで

- (BOOL)shouldAutorotate {
return YES;}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;}

正常に動作しますが、完全ではありません。初めてView Controllerを押したとき、ポートレートモードで表示され(予想どおりランドスケープに制限されません)、デバイス/シミュレーターを回転させて正常に動作し、ランドスケープのみに制限します。

誰でもこれを手伝ってもらえますか?

4

4 に答える 4

1

これを試してみてください。

でこれを呼び出すviewWillAppearと、デバイスに縦向きにジャンプするように明示的に指示されます。

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];

これは正しい解決策ではないと思います。しかし、他に選択肢がない場合は、これを使用できます。ハッピーコーディング:)

于 2012-11-06T09:43:49.533 に答える
0

present new controller:

SecondViewController *objSecondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController presentViewController:objSecondViewController animated:NO completion:^{}];

new controller

- (BOOL)shouldAutorotate {
  return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}
于 2012-11-06T09:44:52.667 に答える
-1

これは私にとってはうまくいきました。これを使ってみてください:

1)YourApp-Info.plist

  • サポートされているインターフェイスの向きの配列をもう 1 つ追加します
  • このディクショナリに必要なオリエンテーションを追加します

以下のスクリーンショットを参照してください。

ここに画像の説明を入力

2)Project Target

  • サポートされているインターフェイスの向きから必要な向きを選択します

以下のスクリーンショットを参照してください。

ここに画像の説明を入力

于 2012-11-06T10:08:40.727 に答える
-2

UIViewController以下の機能を持っています。縦向きを制限したいビューコントローラーでこれを実装できます。

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations

    if(interfaceOrientation == UIInterfaceOrientationPortrait)
        return YES;
    else
        return NO;

    }
于 2012-11-06T09:39:26.733 に答える