如何使用从右到左的 PopAsync 页面导航动画?

问题描述 投票:0回答:2

请告诉我调用 PopAsync() 时如何应用从右到左的动画页面效果。

我的代码:

    async void LogOut_Tapped(object sender, EventArgs e)
    {           
        await Navigation.PopAsync();
    }

请帮助我。

xamarin xamarin.ios xamarin.forms
2个回答
0
投票

PopAsync
有一个 override 接受一个布尔值来指示它是否应该动画。如果您使用
Navigation.PopAsync(true)
调用它,它将在弹出页面时执行动画。


0
投票

你可以尝试https://github.com/AlexandrNikulin/AnimationNavigationPage 惊人的库。以下代码块来自项目自述文件(可能略有改编,归功于Alexandr Nikulin):

用法

public class App : Application
{
        public App()
        {
            MainPage = new AnimationNavigationPage(new YourHomePage());
        }
}

创建 AnimationPage 而不是 ContentPage 并在 xaml 中创建 FadePageAnimation 或 PushPageAnimation 或 FlipPageAnimation 等实例或从 ViewModel 绑定。

<?xml version="1.0" encoding="UTF-8"?>
<controls:AnimationPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:controls="clr-namespace:FormsControls.Base;assembly=FormsControls.Base"
        x:Class="Sample.FadeAnimationPage"
        Title="Fade Animation">
        <controls:AnimationPage.PageAnimation>
            <controls:FadePageAnimation />
        </controls:AnimationPage.PageAnimation>
</controls:AnimationPage>

或者为ContentPage实现接口IAnimationPage。创建 EmptyPageAnimation 或 DefaultPageAnimation 或 FlipPageAnimation 等实例...

public partial class FirstPage : ContentPage, IAnimationPage
{
        public FirstPage()
        {
            InitializeComponent();
        }
    
        public IPageAnimation PageAnimation { get; } = new FlipPageAnimation { Duration = 650, Subtype = AnimationSubtype.FromLeft }; 
}
© www.soinside.com 2019 - 2024. All rights reserved.