2

爲了更好地理解以下問題的,下面是說明我的應用程序的結構的小客廳:http://grab.by/6jXhNavigationController:更換推的UIViewController與另一個

所以,基本上我有一個基於導航的應用程序,它使用NavigationController的「pushViewController」方法顯示視圖A和B.

我想完成的是從視圖A過渡到視圖B,反之亦然。 例如,用戶在主視圖中按下「A」按鈕,使用NavigationController推送視圖A.在這個視圖中,用戶可以按下按鈕「Flip to B」,視圖B替換NavigationController棧上的視圖A(視覺上,這是通過翻轉過渡完成的)。如果用戶按下視圖B上的「後退」按鈕,則會再次顯示主視圖。 要保存已用內存,當前未顯示的視圖(控制器)必須進行處理/卸載/刪除。

什麼是適當的方法來做到這一點?我需要某種類型的ContainerViewController嗎?還是可以不用?

謝謝。

回答

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--這幾乎就是你要找的。

相關問題