3

これは重複した質問ではありません。最終的な実用的な解決策はまだ提供されていないため、回答を受け入れるか、独自の100%実用的な解決策を見つけて提供するまで、この質問を閉じないでください。ありがとう!

================================================== ================
Xcode 4.5.1を使用すると、5つのタブが含まれるタブバーアプリがあります。各タブにはUINavigationControllerが含まれているため、アプリ全体をポートレートモードで表示する必要があります。例外が1つあります。それは、「画像ギャラリー」タイプのビューコントローラであり、開いて全画面表示する必要があり、ランドスケープモードで表示する必要があります。

iOS5では、特定のViewControllerで次のコードを使用してこれを簡単に行うことができました。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

ただしshouldAutorotateToInterfaceOrientation、iOS6では非推奨になり、機能しなくなりました。
したがって、これをiOS6で機能させるために、これまでに次の手順を実行しまし
た。1)UITabBarController(rootViewController)のサブクラスを作成しました。2)とを
設定します (ただし、メソッドを実装していないことに注意してください)。 3 ) PROJECT / Targetでサポートされている向きをALLに設定し ます。このALMOSTは完全に機能します。「ImageGallery」ViewControllerは、両方のランドスケープモードに応答しますが、最初はPortraitで開きます。これは問題です。横向きで開く必要があります。縦向きで表示することはできません。今はまだ両方をやっています。supportedInterfaceOrientationspreferredInterfaceOrientationForPresentationUIInterfaceOrientationMaskPortraitshouldAutorotate



なぜそれを行うのか、またはそれを修正する方法はありますか?

4

2 に答える 2

1

shouldAutorotateToInterfaceOrientationメソッドはiOS6で非推奨になりました

これらの次のメソッドを実装してみてください。

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{   
     // This method is called to determine whether to 
     // automatically forward appearance-related containment
     //  callbacks to child view controllers.
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
    // This method is called to determine whether to
    // automatically forward rotation-related containment 
    // callbacks to child view controllers.
}

注:これらのメソッドはiOS6でサポートされています。

于 2012-11-12T17:58:22.420 に答える
1

私が取り組んでいるアプリでもまったく同じ問題が発生しました。これが私が解決した方法です。

まず、縦向きのコードでUITabBarController呼び出されるのサブクラスを作成しましたNonRotatingTabBarController

NonRotatingTabBarController.h

#import <UIKit/UIKit.h>

@interface NonRotatingTabBarController : UITabBarController
@end

NonRotatingTabBarController.m

#import "NonRotatingTabBarController.h"

@implementation NonRotatingTabBarController

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end

これで、タブバーコントローラーを作成するときに、NonRotatingTabBarControllerのインスタンスである必要があります。

self.tabBarController = [[NonRotatingTabBarController alloc] init]; // or whatever initialising code you have but make sure it's of type NonRotatingTabBarController

ランドスケープをサポートする必要がある唯一のビューコントローラでは、回転するように回転メソッドをオーバーライドする必要があります。私の場合、それは風景に固定する必要がありました

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);
}

- (NSUInteger)supportedInterfaceOrientations 
{
    return UIInterfaceOrientationMaskLandscape;
}

プロジェクト/ターゲット設定では、アプリが使用するすべてのインターフェースの向きに対してサポートを有効にする必要があります。有効にしないと、クラッシュします。上記のコードでローテーションの有効化/無効化を処理します。

Xcodeプロジェクト設定

お役に立てば幸いです。

于 2012-11-01T17:18:51.930 に答える