4

以下情況。 我有一個應用程序使用UINavigationController進行導航。在推送UINavigationController時動畫UIView

對於推動一個特殊的導航控制器我想要一個自定義的動畫,縮小。 我現在看起來不錯,唯一的問題是,「老」Viewcontroller在動畫開始之前消失,所以新的viewcontroller放大了「沒有」,而不是在後臺查看舊的viewcontroller。

爲了更好地觀看我創建了一個簡單的示例應用程序:download

enter image description hereenter image description hereenter image description here

有誰知道,如何動畫新視圖 - 控制(圖像3)舊視圖控制器(圖像1)保持在動畫背景(圖片2)?

/* THIS CANNOT BE CHANGED */ 
    AnimatedViewController *animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil]; 

    /* THIS CAN BE CHANGED */ 
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
    [UIView beginAnimations:@"animationExpand" context:NULL]; 
    [UIView setAnimationDuration:0.6f]; 
    animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1); 
    [UIView setAnimationDelegate:self]; 
    [UIView commitAnimations]; 

    /* THIS CANNOT BE CHANGED */ 
    [self.navigationController pushViewController:animatedViewController animated:NO]; 

附加信息:我的應用程序並不那麼簡單。我爲我的應用程序使用了three20框架,但視圖控制器的推動和創建正是three20所做的。我只能鉤進(我的代碼中的THIS CAN BE CHANGED)之間的部分。我無法在此之前和之後更改代碼(除了大量研究)。

+0

如何設置相同的動畫(啓示方向),同時彈出到原始視圖..? – 2013-03-06 14:37:32

回答

9

我非常快速地鞭打它。這個想法是在縮放動畫完成後調用pushViewController。

-(IBAction)animateButtonClicked:(id)sender { 
    animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil]; 
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    [UIView animateWithDuration:0.6 
        animations:^{ 
         [self.view addSubview:animatedViewController.view]; 
         animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1);      
        } 
        completion:^(BOOL finished){ 
         [animatedViewController.view removeFromSuperview]; 
         [self.navigationController pushViewController:animatedViewController animated:NO]; 
        }]; 

} 
+0

是的,這工作正常(在我的示例應用程序)。但我有一個問題在我的應用程序中使用它。我只能在委託回調中工作:https://gist.github.com/f13b1da4114b7d8691d6在這個委託pushviewcontroller被稱爲 – choise 2011-05-03 20:47:47

+0

後,這裏的問題是,該視圖被渲染兩次。 – choise 2011-05-03 20:53:14

+0

@choise,所以你說的是你不能從函數返回,直到縮放動畫完成(即等待0.6秒),因爲之後直接調用pushViewController? – 2011-05-03 21:07:39

0

好,要做到這一點(有點難看)的一種方式是做動畫,在動畫完成後,執行pushViewController。當您進行動畫製作時,您需要動畫化將要呈現的視圖控制器屏幕的外觀。由於動畫以新視圖結束,所以當新視圖進入屏幕時,不應該改變,因爲它與剛纔的動畫視圖相同。

相關問題