显示pushviewcontroller动画看起来像presentModalViewController

时间:2010-10-01 10:10:09

标签: ios iphone animation pushviewcontroller presentmodalviewcontroller

是否可以将pushViewController动画显示为presentModalViewController但背景功能为pushViewController

5 个答案:

答案 0 :(得分:56)

如果你想要一个淡入淡出的动画,这种方法可行。

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:gridController animated:NO];

答案 1 :(得分:49)

试试这个:

UIViewController *yourViewController = [[UIViewController alloc]init];

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

答案 2 :(得分:24)

用于显示PushViewConttroler动画,因为以下代码正在运行,

推送

 ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
 CATransition* transition = [CATransition animation];
 transition.duration = 0.4f;
 transition.type = kCATransitionMoveIn;
 transition.subtype = kCATransitionFromTop;
 [self.navigationController.view.layer addAnimation:transition
                                                    forKey:kCATransition];
 [self.navigationController pushViewController:VC animated:NO];

POP

CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
                                            forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];

但是有一个问题,它上/下时显示浅黑色背景,
继续努力,一旦完成,就在这里发布新代码。

答案 3 :(得分:1)

适用于Xamarin(C#)的所有等效代码 来自上面的@hardik Thakkar的Answer,在动画过程中遇到黑色背景的问题,一切安好。

对于POP

    CATransition transition = CATransition.CreateAnimation();
    transition.Duration = 0.4;
    transition.Type = CAAnimation.TransitionReveal;
    transition.Subtype = CAAnimation.TransitionFromTop;
    this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));

对于推送

    CATransition transition = CATransition.CreateAnimation();
    transition.Duration = 0.4;
    transition.Type = CAAnimation.TransitionReveal;
    transition.Subtype = CAAnimation.TransitionFromBottom;
    this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));

答案 4 :(得分:0)

您应该考虑做以下事情:

ViewController *myVC = [[ViewController alloc] initWithFrame:OFF_SCREEN];
[navigationController pushViewController:myVC animated:NO];

其中OFF_SCREEN是屏幕下方的一些CGRect,如(0,481,320,480)。然后使用动画块将viewcontroller的视图的frame.origin调整为(0,0)。您可能希望在viewDidLoad或viewDidAppear中执行animate块。