Xamarin Forms Custom Navigation Transitions

痴心易碎 提交于 2021-02-05 06:18:42

问题


I am aware that this question has been asked before but most of them are from over a year ago and I am wondering whether the issue still persists.

Does Xamarin Forms still provide no support on custom navigation page transitions?

I know that you can make animations well in the native applications but it seems from my research that Xamarin Forms requires either a custom renderer or package for doing a simple custom page transition. Has this changed at all or is that still the norm? Hoping they added some form of support since those threads were asked.

Thanks


回答1:


Xamarin.Forms doesn't have the capability to do that, but there's a workaround.

If you disable the animation transition when Pushing or Popping pages, you can do your custom animation before/after the transition.

Like so:

// First animate the opacity of the current page
new Animation(opacity => page.Opacity = opacity / 100, 100, 0)
    .Commit(this, "PageExitAnimation", 1, 350, Easing.CubicInOut, (d, b) =>
    {
         var otherPage = new OtherPage() { Opacity = 0 }; // Create the page with 0 opacity to animate later
         NavigationPage.Navigation.PushAsync(otherPage, false); // Push the new page, as the current page is already with 0 opacity, without animation
         otherPage.FadeTo(1, 350, Easing.CubicInOut); // Animate the fade of the next page
    }

You can apply this concept to do any kind of animation, just instead of modifying the opacity, modify the TranslationY, TranslationX, etc. And if you want a complex animation, you can modify more than one at the same time too, just take your time to learn Xamarin.Forms animation and you're good to go :)

Hope that helps! :D



来源:https://stackoverflow.com/questions/44829066/xamarin-forms-custom-navigation-transitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!