2

私のアプリには 2 つのテーブル ビュー コントローラーが含まれています。最初のものでは、(縦向きモードに加えて)ビューを左右に回転できるようにしたいのですが、2番目のテーブルビューコントローラー(最初のテーブルからセルをタップした後にナビゲートします)では、それが必要ですポートレートモードでのみ表示されます。このコードを試しましたが、うまくいきませんでした。回転し続けます。

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL) shouldAutorotate {
    return NO;
}

注: プロジェクト ターゲットの [概要] タブから、実際に左/右/縦方向を有効にしました。修正はありますか?

4

2 に答える 2

2

次のメソッドを含む UINavigationController のカテゴリを作成します。

(iOS 6 と iOS 5 の両方で動作します)

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

    - (NSUInteger)supportedInterfaceOrientations
    {
        return self.topViewController.supportedInterfaceOrientations;
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

次に、これらのメソッドをコントローラーに実装します

初め:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if (RUNNING_IPAD) {
        return UIInterfaceOrientationMaskAll;
    }
    else {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    };
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (RUNNING_IPAD) {
        return YES;
    }
    else {
        return toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown;
    }
}

そして2番目:

- (BOOL)shouldAutorotate {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
       return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return NO;
}

プロジェクトの回転設定は次のようになります。

設定

于 2013-04-05T13:44:58.493 に答える
0

実際、私は私の問題の解決策を見つけました:

-(BOOL)shouldAutorotate{
    return YES;
}

-(NSInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

これにより、プロジェクトのターゲットの [概要] タブで左右の向きを切り替えた場合でも、ビューが縦向きに制限されます。

于 2013-04-05T14:15:49.413 に答える