[英]Animate the opening of MainPage from App.xaml.cs in Xamarin Forms
When pushing a page in Xamarin Forms I can animate it easily by setting the animate property to true 在Xamarin Forms中推送页面时,我可以通过将animate属性设置为true来轻松地为其设置动画
await Navigation.PushModalAsync(NavigationPageHelper.Create(new MyPage(), true);
How can I achieve the same thing when opening the MainPage from App.xaml.cs, in the App() constructor? 在App()构造函数中从App.xaml.cs打开MainPage时,如何实现相同的功能? I see MainPage as a .Animate extension but I've not found any decent examples of how to use it.
我看到MainPage是一个.Animate扩展,但我没有找到任何关于如何使用它的体面示例。
InitializeComponent();
MainPage = GetMainPage(); // GetMainPage returns the correct page to open
MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White);
UPDATE UPDATE
I found this code to place in the override of OnAppearing, I can see what it should be doing but it doesn't actually do anything, Can anyone see why? 我发现这个代码放在OnAppearing的覆盖中,我可以看到它应该做什么,但实际上并没有做任何事情,任何人都可以看到原因吗?
this.Animate("", (s) => Layout(new Rectangle(X, (1 - s) * Height, Width, Height)), 0, 600, Easing.SpringIn, null, null);
You must set a timeout for the animation to take effect. 您必须设置超时才能使动画生效。
OnAppearing
is called a lot of time before the Page
actually appears. 在
Page
实际出现之前, OnAppearing
被称为很多时间。 Insert your animation in a timeout, like this.. 在超时中插入动画,如下所示..
Task.Delay(1000).ContinueWith(t => BounceUp());
Being BounceUp
your animation story board. BounceUp
你的动画故事板。
Update: You must also use the modifier async
in OnAppearing
method 更新:您还必须在
OnAppearing
方法中使用修饰符async
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.