0

アプリにView Controllerがあります。最初のView Controller、最初のView Controllerが電話の縦向きモードで表示され、ユーザーが横向きモードで電話を回転させると、最初のView Controllerも横向きモードで回転します。

正常に動作し、最初のView Controllerにボタンがあり、ボタンに触れると2番目のView Controllerが表示されます。私がやりたいのは、最初のView Controllerが横向きモードであっても、2番目のView Controllerが常に縦向きモードで表示されるようにすることです。この機能を得るためにオーバーライドしなければならないメソッドはありますか?

4

2 に答える 2

1

ナビゲーション コントローラーでは、コントローラーの向きは、ナビゲーション コントローラーのルート コントローラーの向きに依存します。

次の 2 つの可能性があります。

  1. 実際に表示されるコントローラーに応じて、ルート コントローラーがshouldAutorotateToInterfaceOrientation:異なる値を返すようにします。

  2. ビューコントローラーのビューで変換を使用して、回転させます。

最初の方法を試してみます。方法については、この投稿を参照してください (内容を無視するだけUITabBarControllerです)。または、これを試してください (ナビゲーション階層の最上位のコントローラーにメッセージを中継するだけです)。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {   
    return [self.navigationController.topController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
 }

iOS6 で同じ結果を得るには、次のメソッドを試して定義してください。

-(NSUInteger)supportedInterfaceOrientations {
  return [self.navigationController.topController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  return [self.navigationController.topController  preferredInterfaceOrientationForPresentation];
}
于 2013-01-07T10:29:06.643 に答える
1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

2番目のView Controllerでこれを保持します。

于 2013-01-07T11:24:06.323 に答える