简体   繁体   中英

Xamarin Forms Custom PopAsync Close Animation

Follow this question & answer I have created a new PageRenderer for PushAsync or PushModelAsync works perfect. I would like to make the same animation for PopAsync as the method has a boolean overload for animation Docs . I've done the research and I cannot find anything to do with creating custom animation for this method.

I'm currently only working on Android Solution.

Is it possible? Because currently I have a nice animation for Pushing pages but once I want to get rid of them is just POP as it says in the method name.

Update : I found out that with the same override method OnAttachedToWindow to create an PushAsync animation there is an opposite override OnDetachedFromWindow but the screen disappears before the animation code is executed.

I've added a break point onto the Attached method and Detached and the code does pause at the Detached when PopAsync is executed but no amination comes through. Could this be a BUG ? or is it the actual implementation that is happening under the hood of PopAsync .

Code

protected override void OnDetachedFromWindow()
{
    var myValue = Preferences.Get("ModelAnimationDetach", false);
    if (myValue)
    {
        var metrics = Resources.DisplayMetrics;
        Android.Views.Animations.Animation translateAnimation = new TranslateAnimation(0, metrics.HeightPixels, 0, 0)
        {
            Duration = 2000
        };
        Animation = translateAnimation;
        translateAnimation.Start();
    }

    base.OnDetachedFromWindow();
}

Many Thanks in Advance.

You can use the Shell template to develop the application, the navigation in the Shell has this animation style.

For more information, you can check doc: navigation .

If you don't want to use the shell template, you can try to create the custom NavigationPage renderer to customize the transaction style on each platform.

For this, you can check Xamarin Forms Navigation without animation .

You can also check article Animating Page Transitions in Xamarin Forms .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM