2012-12-14 103 views
4

我有一個小問題。我有一個pushviewcontroller,它使用動畫。 我的代碼是這樣的:如何設置動畫以彈出推送的UIViewController

[UIView beginAnimations: @"Showinfo"context: nil]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDuration:0.75]; 
    [self.navigationController pushViewController:dtv animated:YES]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 
    [UIView commitAnimations];` 

它的工作原理很好,但是當view推我回去,這並不做動畫。 所以當我回去時我不知道如何做同樣的動畫。 任何人都可以幫助我嗎?謝謝!

+1

你實際上是想通過這個做什麼? –

+0

只是推動一個新的視圖控制器,但與動畫。當我回去時,我想要做同樣的動畫。 – andres

回答

2

這就是我一直設法完成這項任務的方式。

推送:

[UIView beginAnimations: @"Showinfo"context: nil]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDuration:0.75]; 
    [self.navigationController pushViewController:dtv animated:YES]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 
    [UIView commitAnimations];` 

對於POP:

[

UIView beginAnimations: @"Showinfo"context: nil]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:0.75]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDelay:0.375]; 
[self.navigationController popViewControllerAnimated:NO]; 
[UIView commitAnimations]; 

我還是從這個,所以我要繼續前進,並更新得到了很多的反饋無論如何,請使用Apple推薦的動畫塊來製作動畫。

推送:

MainView *nextView = [[MainView alloc] init]; 
[UIView animateWithDuration:0.75 
         animations:^{ 
          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
          [super pushViewController:nextView animated:NO]; 
          [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 
         }]; 

對於POP:

[UIView animateWithDuration:0.75 
         animations:^{ 
          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
          [UIView setAnimationTransition:transition forView:self.navigationController.view cache:NO]; 
         }]; 
[self.navigationController popViewControllerAnimated:NO]; 
+0

好多了! ^^ – andres

3

作爲替代,你也可以利用這一點,

CATransition* transition = [CATransition animation]; 
transition.duration = 0.5; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade 
//transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom 
[self.navigationController.view.layer addAnimation:transition forKey:nil]; 
[[self navigationController] popViewControllerAnimated:NO]; 
+0

是的,它的工作原理!謝謝你的幫助! – andres

+0

是的,當然。 – andres

相關問題