[英]Animate the opening of MainPage from App.xaml.cs in Xamarin Forms
在Xamarin Forms中推送頁面時,我可以通過將animate屬性設置為true來輕松地為其設置動畫
await Navigation.PushModalAsync(NavigationPageHelper.Create(new MyPage(), true);
在App()構造函數中從App.xaml.cs打開MainPage時,如何實現相同的功能? 我看到MainPage是一個.Animate擴展,但我沒有找到任何關於如何使用它的體面示例。
InitializeComponent();
MainPage = GetMainPage(); // GetMainPage returns the correct page to open
MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White);
UPDATE
我發現這個代碼放在OnAppearing的覆蓋中,我可以看到它應該做什么,但實際上並沒有做任何事情,任何人都可以看到原因嗎?
this.Animate("", (s) => Layout(new Rectangle(X, (1 - s) * Height, Width, Height)), 0, 600, Easing.SpringIn, null, null);
您必須設置超時才能使動畫生效。 在Page
實際出現之前, OnAppearing
被稱為很多時間。 在超時中插入動畫,如下所示..
Task.Delay(1000).ContinueWith(t => BounceUp());
BounceUp
你的動畫故事板。
更新:您還必須在OnAppearing
方法中使用修飾符async
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.