c# - Xamarin 闪屏
问题描述
我有个问题。我正在尝试为我的背景颜色添加褪色效果,因此我创建了以下代码:
public GetStartedPage()
{
InitializeComponent();
new Task(() => { Animation(); }).Start();
}
private async void Animation()
{
while (true)
{
await this.ColorTo(Color.FromHex("#212121"), Color.FromHex("#5e5e5e"), c => this.BackgroundColor = c, 3000);
await this.ColorTo(Color.FromHex("#5e5e5e"), Color.FromHex("#212121"), c => this.BackgroundColor = c, 3000);
}
}
有了这个扩展:
public static class ViewExtensions
{
public static Task<bool> ColorTo(this VisualElement self, Color fromColor, Color toColor, Action<Color> callback, uint length = 250, Easing easing = null)
{
Func<double, Color> transform = (t) =>
Color.FromRgba(fromColor.R + t * (toColor.R - fromColor.R),
fromColor.G + t * (toColor.G - fromColor.G),
fromColor.B + t * (toColor.B - fromColor.B),
fromColor.A + t * (toColor.A - fromColor.A));
return ColorAnimation(self, "ColorTo", transform, callback, length, easing);
}
public static void CancelAnimation(this VisualElement self)
{
self.AbortAnimation("ColorTo");
}
static Task<bool> ColorAnimation(VisualElement element, string name, Func<double, Color> transform, Action<Color> callback, uint length, Easing easing)
{
easing = easing ?? Easing.Linear;
var taskCompletionSource = new TaskCompletionSource<bool>();
element.Animate<Color>(name, transform, callback, 16, length, easing, (v, c) => taskCompletionSource.SetResult(c));
return taskCompletionSource.Task;
}
}
当我这样做时,屏幕开始闪烁,但没有平滑褪色......
为什么会这样,我该如何解决?
解决方案
推荐阅读
- c++ - 如何在函数重载中推断 lambda 的模板参数?
- javascript - 如何在 JavaScript 中使用 For 循环来显示列表?
- javascript - 为什么 yAxis axisLabel 左对齐是 Apache ECharts 条内的位置标签
- list - 链表中的擦除函数
- c# - 在 C# 中批量更新 mongoDB 文档
- php - 我有一个带有子数组的 multidim 数组,我必须在 php josn 的主索引上只打印 id。我该如何使用循环?
- php - Woocommerce:如何从“process_payment”功能重定向到新页面?
- node.js - 错误 503 服务不可用将 base64 上传到 mysql BLOB
- android - Android 应用程序状态为“生产”,但无法通过提供的链接找到它
- javascript - MUI - 如何响应地获取 theme.mixins.toolbar.minHeight 值?