25

Apples iOS 6 Documentations で説明されているように、コードに新しいメソッドを追加しましたが、iPhone 5 ではアプリが逆さまに回転しません。横向きの方法のみ。

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 は、同じコードで上下逆さまになっています。

何か案は?

4

5 に答える 5

61

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

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

すべてのView Controllerに。これを実行しても機能しない場合は、一部のビューがこれを返さない TabViewController または NavigationController を使用していると確信しています。すべての ViewController がこれをサポートするには、いずれかがこれを返す必要があります。

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

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

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

また、これらは現在 Apple Developer Forums で議論されている現在推奨されているアプローチであり、Apple スタッフは、UINavigationController のサブクラス化を思いとどまらせる以前のドキュメントは時代遅れであり、iOS 6 の時点ではそれを行っても問題ないと述べています。

于 2012-10-06T09:55:43.400 に答える
0

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

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

幸運を :)

于 2012-10-09T17:57:01.803 に答える
0

冗長性を許してください、しかしあなたの答えは以下だと思います。

私は同じ問題を抱えていましたが、iPhone 4を含むすべてのIOS 6デバイスで発生していました.あなたの質問を読んで、実際に私の答えが得られました. 何もしていなかったので、私はこれを何年も前に削除しました:

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

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

では、よろしくお願いします。

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

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

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

お役に立てれば。

于 2012-09-25T20:05:45.377 に答える
0

すべてのビュー コントローラーの回転を有効または無効にする場合は、UINavigationController をサブクラス化する必要はありません。代わりに次を使用します。

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

AppDelegate で。

アプリですべての向きをサポートするが、PARENT ビュー コントローラー (UINavigationController スタックなど) で異なる向きをサポートする予定がある場合は、使用する必要があります。

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

PARENT View Controllerの次のメソッドと組み合わせてAppDelegateから。

    - (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;
}

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

于 2013-01-20T00:47:27.597 に答える