在页面之间导航的自定义动画 Xamarin.forms?

custom animation for navigation between pages Xamarin.forms?

我使用 Xamarin.Forms 创建了一个简单的应用程序,需要将导航设置为上下左右状态

如果你想要上下动画(不是自定义动画),你可以简单地使用 Navigation.PushModalAsync(page) 来呈现页面。


此外,我刚刚编写了一个自定义渲染器来更改 iOS 上的动画。

[assembly: ExportRenderer(typeof(NavigationPage), typeof(AnimationNavigationRenderer))]

class AnimationNavigationRenderer : NavigationRenderer
{
    public override void PushViewController(UIViewController viewController, bool animated)
    {
        if (animated)
        {
            // Alternative way with different set of trannsition
            /*
            UIView.Animate(0.75, () =>
            {
                UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut);
                base.PushViewController(viewController, false);
                UIView.SetAnimationTransition(UIViewAnimationTransition.CurlUp, this.View, false);
            });
             */
            var transition = CATransition.CreateAnimation();
            transition.Duration = 0.75;
            transition.Type = CAAnimation.TransitionPush;

            View.Layer.AddAnimation(transition, null);
            base.PushViewController(viewController, false);
        }
        else
        {
            base.PushViewController(viewController, false);
        }
    }

    public override UIViewController PopViewController(bool animated)
    {
        if (animated)
        {
            // Alternative way with different set of trannsition
            /*                UIView.Animate(0.75, () =>
            {
                UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut);
                UIView.SetAnimationTransition(UIViewAnimationTransition.CurlDown, this.View, false);
            });
            */

            var transition = CATransition.CreateAnimation();
            transition.Duration = 0.75;
            transition.Type = CAAnimation.TransitionFromTop;

            View.Layer.AddAnimation(transition, null);

            return base.PopViewController(false);
        }
        else
        {
            return base.PopViewController(false);
        }
    }
}

https://gist.github.com/alexlau811/e12a8c126e6e082a5017