2

次の質問をよりよく理解するために、ここに私のアプリの構造を示す小さな図があります: http://grab.by/6jXh

したがって、基本的には、NavigationController の「pushViewController」メソッドを使用してビュー A と B を表示するナビゲーション ベースのアプリがあります。

私が達成したいのは、ビュー A からビュー B へ、またはその逆に移行することです。たとえば、ユーザーがメイン ビューで「A」ボタンを押すと、NavigationController を使用してビュー A がプッシュされます。このビューで、ユーザーは「Flip to B」ボタンを押すことができ、ビュー B が NavigationController のスタック上のビュー A を置き換えます (視覚的には、これはフリップ遷移を使用して行われます)。ユーザーがビュー B の「戻る」ボタンを押すと、メイン ビューが再び表示されます。使用済みメモリを節約するには、現在表示されていない View(Controller) の割り当てを解除/アンロード/削除する必要があります。

これを行う適切な方法は何ですか?ある種の ContainerViewController が必要ですか、それともなしで実行できますか?

ありがとう。

4

1 に答える 1

0

ContainerViewController クラスを作成して、次のようにプッシュできます。

ContainerViewController *containerViewController = [[ContainerViewController alloc] initWithFrontView: YES];
[self.navigationController pushViewController: containerViewController animated: YES];
[containerViewController release];

クラスは次のようになります: (前面ビューまたは背面ビューを上にしてプッシュできるため)

- (id)initWithFrontView: (BOOL) frontViewVisible {
    if (self = [super init]) {
        frontViewIsVisible = frontViewVisible;

        viewA = [[UIView alloc] init];
        viewB = [[UIView alloc] init];

        if (frontViewIsVisible) {
            [self.view addSubview: viewA];
        }
        else {
            [self.view addSubview: viewB];
        }


        //add a button that responds to @selector(flipCurrentView:)
    }
    return self;
}

- (void) flipCurrentView: (id) sender {
       [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];

        if (frontViewIsVisible == YES) {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: self.view cache:YES];
            [viewA removeFromSuperview];
            [self.view addSubview: viewB];
        } else {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView: self.view cache:YES];
            [viewB removeFromSuperview];
            [self.view addSubview: viewA];
        }

        [UIView commitAnimations];

        frontViewIsVisible =! frontViewIsVisible;
    }

そして、メモリ管理に注意することを忘れないでください。また、 http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.htmlを参照することをお勧めします。これは、まさに探しているものです。

于 2011-03-12T16:18:49.327 に答える