3

通常は縦向きのアプリで、1 つの UIViewController に対して横向きのビューのみを表示するアプリケーションがあります。新しい iOS 6 がリリースされるまでは問題なく動作します。

iOS 6 で方向がどのように機能するかがよくわかりません。そのため、テスト アプリを作成しました。これが私がしたことです:

  • すべての向きをサポートするようにアプリケーションの向きを設定します。

ここに画像の説明を入力

  • ストーリーボードを使用しています。rootViewController は、縦向きの UINavigationController に埋め込まれています。

ここに画像の説明を入力

  • rootViewController のコード:

    -(NSUInteger)サポートされているインターフェイスの向き

    {

    UIInterfaceOrientationMaskPortrait を返します | UIInterfaceOrientationMaskPortraitUpsideDown;

}

  • [バーを開く] ボタンをクリックすると、別の (SecondViewController) ビュー コントローラーが横向きモードになるはずです。

    -(NSUInteger)supportedInterfaceOrientations { UIInterfaceOrientationMaskLandscapeLeft を返す | UIInterfaceOrientationMaskLandscapeRight; }

このメソッドは正しく呼び出されますが、2 番目のビュー コントローラーも常に縦長モードになります。

誰か私にいくつかの提案をしてもらえますか? ありがとう

4

3 に答える 3

1

これが私の解決策です:

2番目のビューコントローラのviewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIViewController *viewController = [[UIViewController alloc] init];
    [self presentViewController:viewController animated:NO completion:^{
        [viewController dismissViewControllerAnimated:NO completion:nil];
    }];
}

これにより、2番目のビューが横向きに回転し、問題が解決しました。そしてそれはiOS5と6で動作します。

于 2012-10-10T05:49:16.733 に答える
1

iOS-6の場合、これを行いました。元気に走っています

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;}

2 番目のビューで

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;}
于 2012-12-21T05:25:48.937 に答える
0

最善の解決策は、アップルの公式ドキュメントに固執することだと思います。したがって、私は次のメソッドを使用し、すべてが iOS 5 および 6 で非常にうまく機能しています。すべての ViewControllers で、次のメソッドをオーバーライドします。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

iOS 6 のメソッド。最初のメソッドは、サポートされている方向マスクを返します (その名前が示すように)。それを横向きまたは最適なスイートに変更できます。

-(NSInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ... 
}

2 つ目は、VC が表示されるときにどのインターフェイスの向きが優先されるかを VC に伝えます。

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}

このソリューションはスムーズに機能しています。この単純なソリューションを回避するマクロやその他のものを作成するという考えは好きではありません。この助けを願って...

于 2012-11-28T07:40:15.040 に答える