36

iOS 6 SDK でこの問題が発生しています。回転を許可する必要のあるビュー (ビデオビューなど) とそうでないビューがあります。これで、アプリの Info.plist ですべての向きを確認し、各 ViewController で何が起こるかを整理する必要があることがわかりました。しかし、それはうまくいきません!アプリは常に Info.plist で指定された方向に回転します。

Info.plist:

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

回転を許可しない ViewController:

//deprecated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

観察: アプリは横向きと縦向きに回転します。なぜ、または私が間違っているのか、何か考えはありますか?

乾杯、マーク

編集: 私の最新の調査結果は、アプリのある時点で回転させたい場合は、プロジェクト設定または Info.plist で 4 つの回転方向すべてを有効にする必要があることも示しています。これに代わる方法は、オーバーライドすることです

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

Info.plist をオーバーライドする AppDelegate で。Info.plist で Portrait のみを設定してから、shouldAutorotateToInterfaceOrientation または supportedInterfaceOrientations をオーバーライドして一部の ViewController で回転させることはできなくなりました。

4

9 に答える 9

31

ViewController が UINavigationController または UITabBarController の子である場合、問題は親です。質問で示したように、これらの InterfaceOrientation メソッドをオーバーライドするだけで、その親ビュー コントローラーをサブクラス化する必要がある場合があります。

編集:

縦長のみの例 TabBarController

           @interface MyTabBarController : UITabBarController
            {
            }
            @end

            @implementation MyTabBarController

            // put your shouldAutorotateToInterfaceOrientation and other overrides here        
            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
                return (interfaceOrientation == UIInterfaceOrientationPortrait);
            }

            - (NSUInteger)supportedInterfaceOrientations{ 
                return UIInterfaceOrientationMaskPortrait; 
            } 

        @end
于 2012-09-13T17:27:39.897 に答える
27

上記のCSmithの回答に加えて、UINavigationControllerサブクラスの次のコードにより、最初にこれが機能すると予想した方法でトップビューコントローラーへの委任が可能になります。

- (BOOL)shouldAutorotate;
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if ([[self topViewController] respondsToSelector:@selector(supportedInterfaceOrientations)])
        return [[self topViewController] supportedInterfaceOrientations];
    else
        return [super supportedInterfaceOrientations];
}
于 2012-09-20T06:31:08.177 に答える
8

CSmith のアプローチの別の方法を次に示します。

ナビゲーション スタック/タブ バーのすべてのビューが、許容される向きのセットに同意する必要がある iOS 6 以前の動作を複製する場合は、これをUITabBarControllerまたはのサブクラスに入れUINavigationControllerます。

- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger orientations = [super supportedInterfaceOrientations];

    for (UIViewController *controller in self.viewControllers)
        orientations = orientations & [controller supportedInterfaceOrientations];

    return orientations;
}
于 2012-10-19T12:21:17.090 に答える
0

@CSmith と @EvanSchoenberg へのさらなる追加。

回転するビューと回転しないビューがある場合は、 のカスタム インスタンスを作成する必要がありますが、それぞれに決定をUITabBarController任せます。UIViewController

- (BOOL)shouldAutorotate;
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController * top;
    UIViewController * tab = self.selectedViewController;
    if([tab isKindOfClass:
        ([UINavigationController class])]) {
        top = [((UINavigationController *)tab)
                 topViewController];
    }

    if ([top respondsToSelector:@selector(supportedInterfaceOrientations)])
        return [top supportedInterfaceOrientations];
    else
        return [super supportedInterfaceOrientations];
}
于 2014-07-12T19:57:00.227 に答える
-2

別のオプションとして、アプリで iOS6 より前の回転機能を維持したい場合は、次のようにします。

これは、iOS4/iOS4 で行ったようにローテーションが機能するように、iOS6 のメソッド呼び出しをスウィズルする github の便利なコードです。ローテーションを実際に細かく管理するレガシーアプリをサポートしているので、これは本当に役に立ちました。iOS6 に必要な変更を実装するには、多くの作業が必要でした。投稿してくれたユーザーに敬意を表します。

https://gist.github.com/3725118

于 2012-09-19T17:35:39.037 に答える