web-dev-qa-db-ja.com

iPhone5が逆さまに回転しない理由

apples iOS 6のドキュメントで説明されているように、新しいメソッドをコードに追加しましたが、iPhone5ではアプリが上下逆に回転しません。ランドスケープウェイのみ。

これがrootViewControllerからの私のコードです:

- (NSUInteger)supportedInterfaceOrientations{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return YES;
}

「UIInterfaceOrientationMaskAll」も試しましたが、変更はありません。奇妙なことに、iOS6を搭載した私のiPhone 4は、同じコードで逆さまになっています。

何か案は?

25

IOS 6は、iPadの場合はデフォルトの方向UIInterfaceOrientationMaskAll、iPhoneの場合はUIInterfaceOrientationMaskAllButUpsideDownを使用します。 iPhoneのViewControllerをUpsideDownを含むすべての方向に回転させる場合は、iOS6メソッドを追加する必要があります。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

すべてのビューコントローラに。これを実行しても機能しない場合は、一部のビューがこれを返さないTabViewControllerまたはNavigationControllerを使用していると思います。すべてのViewControllerは、これをサポートするために、これを返す必要があります。

または、rootViewControllerであるUITabViewControllerまたはNavigationControllerクラスにカテゴリを追加し、そのメソッドをオーバーライドすることもできます。あなたはそうするようにします:

@interface UITabBarController (RotationAll)
    -(NSUInteger)supportedInterfaceOrientations;
@end

@implementation UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
@end

また、これらは現在Apple Developer Forums with Appleスタッフが、UINavigationControllerのサブクラス化を推奨していないという以前のドキュメントは古くなっていると言っている現在推奨されているアプローチです。 iOS 6の時点では、それを実行しても問題ありません。

61
Cliff Ribaudo

Cliff Ribaudoのおかげで、UITabbarControllerベースのプロジェクトに対する回答を完全に得ることができますが、私の場合はUINavigationControllerのみを使用しているため、UINavigationControllerカテゴリの回答を変更しました。

@interface UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end   


@implementation UINavigationController (RotationAll)
  -(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
  }
@end
12
Chandan

デフォルトのターゲット設定は逆さまではないので、これを試してください。

プロジェクトファイルに移動し、アプリのターゲットを選択します。[夏]タブを選択し、すべての方向タイプが押されていることを確認します

幸運を :)

0
avishic

すべてのViewControllerの回転を有効または無効にする場合は、UINavigationControllerをサブクラス化する必要はありません。代わりに以下を使用してください。

   -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

appDelegateで。

アプリですべての方向をサポートする予定であるが、PARENT View Controller(UINavigationControllerスタックなど)で異なる方向をサポートする場合は、次を使用する必要があります

   -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

appDelegateから、PARENT ViewControllerの次のメソッドと組み合わせて使用​​します。

    - (BOOL)shouldAutorotate

そして

- (NSUInteger)supportedInterfaceOrientations

ただし、同じナビゲーションスタック(私のように)内の異なるCHILDREN ViewControllerで異なる方向設定を計画している場合は、ナビゲーションスタック内の現在のViewControllerを確認する必要があります。

UINavigationControllerサブクラスで次を作成しました。

    - (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    int interfaceOrientation = 0;

    if (self.viewControllers.count > 0)
    {
        id viewController;
        DLog(@"%@", self.viewControllers);
        for (viewController in self.viewControllers)
        {
            if ([viewController isKindOfClass:([InitialUseViewController class])])
            {
                 interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
            }
            else if ([viewController isKindOfClass:([MainViewController class])])
            {
                 interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
            }
            else
            {
                 interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
            }
        }
    }
    return interfaceOrientation;
}

子ViewControllerから表示されたViewControllerの回転設定を制御できなくなったため、ナビゲーションスタックに現在あるViewControllerを何らかの方法でインターセプトする必要があります。それが私がしたことです:)。お役に立てば幸いです。

0
Razvan

冗長性は許しますが、あなたの答えは以下のとおりだと思います。

私は同じ問題を抱えていましたが、それは私のiphone4を含むすべてのIOS 6台のデバイスで発生していました。あなたの質問を読んで実際に私の答えが返ってきました。 :

- (NSUInteger)supportedInterfaceOrientations{    
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown); }

私のコードは以前のiOSリリースで完全に機能していました。これはiOS6では必須になっているようです。ただし、upsideDownの場合のみです。他のオリエンテーションはうまく機能していました。

だから、ありがとう。

問題に戻ります。プロジェクトターゲットを確認して、すべての「サポートされているインターフェイスの向き」が濃い灰色であるかどうかを確認しましたか?逆さまが薄い灰色(つまり、チェックされていない)かどうか疑問に思います。クイックテストで、以前のiosリリースではこれらも無視されていることがわかりました。 shouldAutorotateToInterfaceOrientationからYESを返す限り、方向はサポートされますが、iOS6ではサポートされません。

最後に、shouldAutorotateを実装しましたが、これはコードにはありません。これはデフォルトで「はい」になっていると思います。そして、これはOSに回転を試みるように指示するだけだと思いますが、shouldAutorotateToInterfaceOrientationでサポートする方向を指示する必要があります。ただし、スニペットには、shouldAutorotateToInterfaceOrientationを実装したことが示されていません。これを実装することをお勧めします。これは、サポートする方向をOSに通知するため、単純なYESを返すことは、すべてをサポートすることを意味します。

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

お役に立てれば。

0
krason