5

縦向きのみをサポートする iPhone アプリケーションがあります。横向きのみをサポートするビュー コントローラーをプロジェクトに追加したいですか? 出来ますか?はいの場合、どうすればそれを達成できますか?

次のようなカテゴリファイルを作成しようとしました:

@implementation UINavigationController (Rotation_IOS7)

-(BOOL)shouldAutorotate
    {

        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {

      return UIInterfaceOrientationMaskLandscape;

    }

これを行うと、次のエラーが表示されます: Terminating app due to uncaught exception UIApplicationInvalidInterfaceOrientation, reason:Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

4

3 に答える 3

1

私は数多くのトピックを検索し、最終的に有効な解決策を見つけました。

私の例では、2 つの VC があります。

A -> Nav 内に組み込まれている VC。Controller であり、Portrait ビューのみをサポートする必要があります。

B -> VC 内に埋め込まれておらず、ランドスケープのみをサポートする必要がある VC。

ビューAからビューBに(ボタンを押すことで)移動し、特定の向きがまだ正しい状態でビューAに戻りたいと思います。

I. UINavigationController のカテゴリを作成し、.m ファイルに次のように記述します (コードは自動的に呼び出されます)。

- (NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"supportedInterfaceOrientations = %d ", [self.topViewController         supportedInterfaceOrientations]);

    return [self.topViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{
    // You do not need this method if you are not supporting earlier iOS Versions

    return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

Ⅱ.A と B の間にモーダル セグエを作成し、その後 B と A の間に別のモーダル セグエを作成します。

III. 各 View Controllers .m ファイルに次の内容を書き留めます。

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

また

- (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }

このコードを追加した後。単一ビュー B の向きを変更できます。

于 2014-05-13T09:12:03.197 に答える
0

編集:

.h でカテゴリを作成し、それらのメソッドを実装します

ランドスケープをサポートするView Controllerでこれらのメソッドを使用します

@implementation UINavigationController (Rotation_IOS7)

-(BOOL)shouldAutorotate
    {

        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {

      return UIInterfaceOrientationMaskLandscape;

    }
于 2013-11-11T11:33:02.720 に答える