如何设置动画以弹出推送的UIViewController

4

我有一个小问题。我使用了pushviewcontroller并且它使用了动画效果。 我的代码如下:

   [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
你实际上想通过这个做什么? - DD_
只需推送一个新的视图控制器,但带有动画效果。当我返回时,希望视图执行相同的动画。 - andres
2个回答

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];

2

这是我一直以来完成这项任务的方式。

对于Push:

[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];`

对于弹出:

[

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];

我仍然收到很多反馈,所以我打算更新它以使用动画块,这也是苹果推荐的动画方式。
对于Push:
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];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接