1

在我的庫中,我有一個加載視圖,它彈出到輸入視圖。當用戶完成輸入視圖時,它應該返回到加載視圖以再次執行一些魔術,並在完成時顯示第三個視圖。popToRootViewController轉發動畫

現在,從可用性視圖中,我不想「滑回」到加載視圖,我也不想在已經有內存的情況下分配新的加載視圖。

有沒有什麼辦法可以popToRootViewController同時向前滑動視圖? (是的,我刪除加載視圖中的後退按鈕)..

回答

2

好吧這裏去 - 也許嘗試使用這樣的事情

// This goes in whatever view controller you want to pop with 
- (void)popToRootWithForwardAnimation 
{ 
    NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease] 
    UIViewController * rootViewController = [viewControllers objectAtIndex:0] 
    [viewControllers removeObjectAtIndex:0]; // try using with and without this line? 
    [viewControllers addObject:rootViewController]; 

    [self.navigationController setViewControllers:viewControllers animated:YES]; 
} 

// This goes in the root view controller 
- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated] 
    NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease] 
    if ([viewControllers count] > 1) 
    { 
     [viewControllers removeAllObjects]; 
     [viewControllers addObject:self]; 

     [self.navigationController setViewControllers:viewControllers animated:NO]; 
    } 

    … 
    … 
} 
2

嗯,我想說一個更好的方法是翻轉視圖模式的方式,而不是在導航堆棧推/彈出。所以,你想在輸入視圖做,你正在推動下一個視圖控制器:

MagicViewController *magicVC = [[MagicViewController alloc] init]; 
magicVC.setModalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:magicVC animated:true]; 

然後,當魔術視圖控制器完成做它的魔力,只是做在這一點(在那裏你,否則POP):

[self dismissModalViewControllerAnimated:true]; 

這比做簡單的導航要冷得多。

See modal view controllers guide.

+0

我這個答案達成一致。然而,在回答你的原始問題時,是的,你可以通過在UINavigationController上使用viewControllers和setViewController:動畫屬性來「強制」前進動畫。 – mackross

+0

你可以隨時投票,如果你同意:) – zakishaheen

+0

哈哈沒有後顧之憂。 – mackross