ios 显示 pushviewcontroller 动画看起来像 presentModalViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3838219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:49:35  来源:igfitidea点击:

Showing pushviewcontroller animation look like presentModalViewController

iosiphoneanimationpushviewcontrollerpresentmodalviewcontroller

提问by sathish kumar

Is it possible to show pushViewControlleranimation look like presentModalViewControllerbut that has background functionality of pushViewController?

是否可以显示pushViewController动画看起来像presentModalViewController但具有背景功能pushViewController

回答by steipete

If you want to a fade animation, this approach works.

如果您想要淡入淡出动画,这种方法有效。

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

回答by jithinroy

Try this :

尝试这个 :

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

回答by Dilip

For display PushViewConttroler animation as Present below code is working,

为了显示 PushViewConttroler 动画,下面的代码正在工作,

For Push

对于推送

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

And for POP

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

There is 1 issue though, that its display light black background when its going up/down,
Working on that, As soon as its done post new code here.

但是有一个问题,它在上升/下降时显示浅黑色背景,正在处理
,一旦完成就在此处发布新代码。

回答by soan saini

For All Trying in Xamarin (C#) equivalent Code From Answer by @hardik Thakkar above, Has the issue of Black backgound during animation, rest all good.

对于所有尝试在 Xamarin (C#) 等效代码中来自 @hardik Thakkar 上面的回答,动画期间出现黑色背景问题,一切都好。

For 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));

For Push

对于推送

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

回答by kevboh

You should consider doing something like:

您应该考虑执行以下操作:

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

where OFF_SCREEN is some CGRect below the screen, like (0, 481, 320, 480). Then use an animation block to adjust the viewcontroller's view's frame.origin to be (0, 0). You would probably want to do the animate block in viewDidLoad or viewDidAppear.

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