0

わかりました。前の質問に誰も答えなかったので、これを行う簡単な方法はないかもしれないと信じるようになりました. しかし、私は楽観的です。これが私の問題です:

私のアプリでは、通常の UIButton を使用して ViewControllerOne から ViewControllerTwo に切り替えています。ViewControllerOne は常に横向きモードです。ViewControllerTwo は常に縦向きモードになっているはずです。ただし、横向きのViewControllerOneでボタンを押すと、ViewControllerTwoも横向きモードになりますが、ボタンを押したときにユーザーがデバイスをどのように回転させても縦向きモードに切り替えたいと思います。

AppDelegate に次のコードを追加しました。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskAll;

    if (self.window.rootViewController) {
        UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presented supportedInterfaceOrientations];
    }
    return orientations;
}

そして、縦向きモードのみであるはずのViewControllerにこれを追加しました:

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

- (BOOL)shouldAutorotate
{
    return NO;

}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;

}

-(void)viewWillAppear:(BOOL)animated
{
    UIApplication* application = [UIApplication sharedApplication];
    application.statusBarOrientation = UIInterfaceOrientationPortrait;
}

前のビューが横向きだったとしても、viewController を縦向きモードにする方法はありますか? ボタンが押されたときにビューを強制的にポートレート モードにするカスタム セグエを作成できますか? ここでの最良の/公式の解決策は何ですか?

4

2 に答える 2