【问题标题】:Xamarin Forms Custom Navigation TransitionsXamarin 表单自定义导航转换
【发布时间】:2017-06-30 06:16:38
【问题描述】:

我知道以前有人问过这个问题,但其中大多数是一年多以前的问题,我想知道这个问题是否仍然存在。

Xamarin Forms 是否仍然不支持自定义导航页面转换?

我知道您可以在本机应用程序中很好地制作动画,但从我的研究来看,Xamarin Forms 似乎需要自定义渲染器或包来执行简单的自定义页面转换。这完全改变了还是这仍然是常态?希望他们在询问这些线程后添加某种形式的支持。

谢谢

【问题讨论】:

标签: c# xamarin xamarin.ios xamarin.forms


【解决方案1】:

Xamarin.Forms 无法做到这一点,但有一种解决方法。

如果您在推送或弹出页面时禁用动画转换,您可以在转换之前/之后进行自定义动画。

像这样:

// 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
    }

你可以应用这个概念来做任何类型的动画,而不是修改不透明度,修改TranslationY,TranslationX等。如果你想要一个复杂的动画,你也可以同时修改多个,花点时间学习 Xamarin.Forms 动画,一切顺利:)

希望对您有所帮助! :D

【讨论】:

  • 我不这么认为...不过很简单,不是直接调用PushAsync,而是调用我在答案上写的代码。您可以将此代码包装在一个单独的方法中,并调用此方法而不是 PushAsync。花点时间了解代码的作用,然后适应PopAsync 方法。它也应该很简单,因为唯一的变化是您需要在调用 PopAsync 之前更改不透明度(而不是在调用 PushAsync 之后。但是如果您只为 Android 和 iOS 开发,您可以使用作为评论提到的插件。希望这会有所帮助:)
猜你喜欢
  • 2021-11-04
  • 1970-01-01
  • 2021-02-24
  • 2020-06-12
  • 1970-01-01
  • 2018-03-23
  • 2018-04-28
  • 2017-01-24
  • 1970-01-01
相关资源
最近更新 更多