3

すべてのView Controllerが縦向きモードのみをサポートするようにしたいのですが、1つのView Controllerを除いて、横向きモードもサポートする必要がある「LandscapeSupportViewController」と呼ぶことができます。

問題は、LandscapeSupportViewController をランドスケープ モードにしてから、ポートレート モードのみをサポートする新しいビュー コントローラーをプッシュすると、プッシュされたビュー コントローラーもランドスケープ モードになることです。強制的にポートレートにするにはどうすればよいですか?

それを行うアプリはほとんど見ませんでした。たとえば、Skype iPhoneアプリの場合、[メッセージ]タブは縦向きのみです->メッセージ自体を入力するために押すと、横向きをサポートするビューコントローラーも取得されます。ユーザーがチャット中-> を押して人物のプロフィールを表示すると、新しいビュー コントローラーが縦向きにプッシュされます。元に戻すと同じことが起こり、横向きから来た場合でも縦向きに戻らざるを得なくなります...

ありがとう

4

4 に答える 4

1

これが解決策です。ビュー コントローラーの向きを管理する UINavigationController のカテゴリを追加できます。以下のコードを参照してください。

@interface UINavigationController (MyViewOrientations)
@end

@implemetation UINavigationController (MyViewOrientations)

- (BOOL)supportLandscapeModeForViewController:(UIViewController *)controller {
    return [controller isKindOfClass:[LandscapeSupportViewController class]]
}

- (NSUInteger)supportedInterfaceOrientation {
    UIViewController *controller = [self visibleViewController];
    NSUInteger orientationMasks = UIInterfaceOrientationMaskPortrait
    if([self supportLandscapeModeForViewController:controller]) {
        orientationMasks |= UIInterfaceOrientationMaskLandscapeLeft;
        orientationMasks |= UIInterfaceOrientationMaskLandscapeRight;
    }
    return orientationMasks;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    UIViewController *controller = [self visibleViewController];
    if([self supportLandscapeModeForViewController:controller]) {
        return UIInterfaceOrientationLandscapeLeft; // Your call
    }
    else {
        return UIInterfaceOrientationPortrait;
    }
}

- (BOOL)shouldAutorotate {
    UIViewController *controller = [self visibleViewController];
    return [self supportLandscapeModeForViewController:controller];
}
@end

状況がより複雑な場合、さまざまなビューがさまざまな方向性をサポートします。ビューコントローラーで「supportedInterfaceOrientation」、「preferredInterfaceOrientationForPresentation」、「shouldAutorotate」をオーバーライドし、UINavigationController カテゴリコードからの呼び出しを「visibleViewController」でデリゲートできます。

于 2013-07-21T09:16:15.157 に答える
1

私は生徒たちに、あなたが達成しようとしていることを正確に達成しようとしてもらいました。多くの調査の結果、一般的なコンセンサスは次のとおりです。これは悪い考えであり、達成するには多くの (App Store の合法的な) ハックが必要であり、それでも達成されません。きれいすぎることが判明しました(たとえば、ステータスバーが台無しになります)。Skype アプリで、IM セクションに移動して横向きに回転し、元に戻すと、UI が「スナップ」するか、すぐにリロードされることに気付くでしょう。

これはユーザー エクスペリエンスが良くないため、デザインを再考して、Apple の推奨事項にさらに沿うようにすることをお勧めします。

于 2012-06-07T14:15:41.877 に答える
1

Write this lines before you push viewController which supported only portrait From landscapeViewController

[appdel.navigationController.view removeFromSuperview];// This navcontroller used with rootviewcontroller
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
[ [UIApplication sharedApplication].self.delegate.window addSubview:appdel.navigationController.view];
self.navigationController.navigationBar.hidden=NO;
于 2012-06-07T14:40:03.003 に答える
1

私が正しく理解した場合、いくつかの条件でデバイスの向きを変更したいと考えています。

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];

上記の行を使用して独自の向きを設定します。この行を if 条件の中に入れるだけです。状態はあなた次第です。

ありがとうございました!!

于 2012-06-07T14:19:00.267 に答える