2

ビューアニメーションを使用してビューを切り替えていますが、インターフェイスの向きに問題があります。

ウィンドウには2つのビューがあります。

  1. authenticationViewCont
  2. mainViewCont

どちらにもボタンがあり、ボタンをクリックするauthenticationViewContと削除して表示mainViewContし、その逆も同様です。

addSubview を追加しauthenticationViewCont.viewてデバイスを縦向きモードにしてから削除したら、removeFromSuperviewデバイスの向きを手の中で横向きに変更してから、もう一度 addSubview をauthenticationViewCont. 最初に縦向きのアニメーションを表示し、アニメーション後に向きを変更しました。

-(void)mainToAuthentication {
    CGRect originalFrame = authenticationViewCont.view.frame;
    CGRect modifiedFrame = originalFrame;
    modifiedFrame.origin.y = originalFrame.size.height;
    // made view out from screen
    authenticationViewCont.view.frame = modifiedFrame;
    // add sub view on top of other views
    [self.window addSubview:authenticationViewCont.view];
    // transiting view from bottom to center of screen
    [UIView animateWithDuration:0.5
        animations:^{ authenticationViewCont.view.frame = originalFrame; }
        completion:^(BOOL finished){ mainViewCont.view removeFromSuperview; }];
}

-(void)authenticationToMain {
    CGRect originalFrame = mainViewCont.view.frame;
    CGRect modifiedFrame = originalFrame;
    modifiedFrame.origin.y = -originalFrame.size.height;
    // made view out from screen
    mainViewCont.view.frame = modifiedFrame;
    // add sub view on top of other views
    [self.window addSubview:mainViewCont.view];
    // transiting view from top to center of screen
    [UIView animateWithDuration:0.5
        animations:^{ mainViewCont.view.frame = originalFrame; }
        completion:^(BOOL finished){ authenticationViewCont.view removeFromSuperview; }];
}

以前のインターフェイスの向きではなく、現在のインターフェイスの向きで表示するにはどうすればよいremoveFromSuperviewですか?

4

1 に答える 1

0

ここでの問題は、最初に1つのviewController.viewを別のviewController.viewの上に追加してから、古いものを削除していることだと思います。

ウィンドウの問題は、rootViewController を 1 つしか想定していません。したがって、ウィンドウは回転イベントのみを最初のコントローラーに渡します。2 番目の viewController は、completesBlock が呼び出されるまで回転イベントを取得しないことを意味します。

これを回避する方法は、ウィンドウ上にある rootViewController 内にこの切り替えコードを配置することです。次に、切り替えを行うたびに、rootviewController の現在のローテーションを渡し、渡した向きに基づいて authenticationViewController を設定することができます。

于 2011-08-20T15:58:10.737 に答える