Animation Xamarin动画导致我的应用程序跳过许多帧
我有一个主视图页面,带有一个框架和图像(位于可绘制文件夹内)。在后端,我做了3秒钟的简单动画 我的问题: 我怎么做了太多的工作,简单的动画和图像是500x500。如何修复此错误 顺便说一下,如果我删除动画代码Animation Xamarin动画导致我的应用程序跳过许多帧,animation,xamarin.forms,xamarin.android,Animation,Xamarin.forms,Xamarin.android,我有一个主视图页面,带有一个框架和图像(位于可绘制文件夹内)。在后端,我做了3秒钟的简单动画 我的问题: 我怎么做了太多的工作,简单的动画和图像是500x500。如何修复此错误 顺便说一下,如果我删除动画代码Task.whalll Thread started: #5 [Choreographer] Skipped 1191 frames! The application may be doing too much work on its main thread. [ViewRootImp
Task.whalll
Thread started: #5
[Choreographer] Skipped 1191 frames! The application may be doing too much work on its main thread.
[ViewRootImpl@5028d58[MainActivity]] dispatchAttachedToWindow
[me.idcardwalle] Explicit concurrent copying GC freed 1534(155KB) AllocSpace objects, 0(0B) LOS objects, 69% free, 2MB/8MB, paused 53us total 16.620ms
[Mono] GC_TAR_BRIDGE bridges 168 objects 168 opaque 0 colors 168 colors-bridged 168 colors-visible 168 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.05ms tarjan 0.04ms scc-setup 0.05ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.03ms
[Mono] GC_BRIDGE: Complete, was running for 17.71ms
[Mono] GC_MINOR: (Nursery full) time 3.13ms, stw 4.30ms promoted 158K major size: 3984K in use: 3218K los size: 4096K in use: 3634K
...
[Choreographer] Skipped 40 frames! The application may be doing too much work on its main thread.
[ViewRootImpl@5028d58[MainActivity]] MSG_RESIZED: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 63 - 0, 126) vi=Rect(0, 63 - 0, 126) or=1
[InputMethodManager] prepareNavigationBarInfo() DecorView@a5c60a8[MainActivity]
[InputMethodManager] getNavigationBarColor() -855310
动画代码
protected override async void OnAppearing()
{
base.OnAppearing();
ssImage.Opacity = 50;
await Task.WhenAll(
ssImage.FadeTo(1, 3000),
ssImage.ScaleTo(1.2, 3000)
);
var route = $"{ nameof(NewPage)}";
await Shell.Current.GoToAsync(route);
}
用户界面代码
<Frame VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Padding="0" Margin="0">
<Frame.Background>
<LinearGradientBrush>
<GradientStop Color="#0087c8" Offset="0.1" />
<GradientStop Color="#005783" Offset="1.0" />
</LinearGradientBrush>
</Frame.Background>
<Image x:Name="ssImage" Source="ssImage.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
HeightRequest="300"
WidthRequest="300" />
</Frame>
on显示
发生在页面显示之前
若要获得平滑的动画,您希望页面在动画开始之前完成显示。这需要进行以下两项代码更改:
不清楚您试图解决的问题是什么?是否存在实际错误?什么东西特别慢?您正在运行6秒的动画,这似乎是一个巨大的时间-默认值为0.25秒。动画是UI操作,必须在UI线程上运行。我只运行3秒而不是6秒的动画。我正在尝试修复错误(跳过1191帧)。让我知道,我可以添加更多不是错误的细节。安卓一直在生成这些日志消息。只是为了确保。你是说我应该忽略这条消息,因为它的android一直在生成它?由于跳过了这么多帧,我的“建筑”菜单幻灯片动画冻结,并陷入lil。而且它并不平滑。如果删除此动画,则菜单幻灯片动画是平滑的。我需要lil帮助修复此消息,使其不会跳过太多帧。跳过少于100帧可以,但不是1000帧。有什么想法吗?我甚至不知道我还能做些什么来调试?“我的应用程序中也有滚动问题,其中一些帧被跳过”-滚动“打嗝”通常有不同的原因。如果这里的答案没有帮助,那么开始一个新的问题,并附上相关的代码。谢谢你,我说得通。我在OnAppearing中添加了这段代码,但是动画(缩放/淡入)不起作用(它通过动画跳过)。也许我错过了什么?我的错。。。你的代码工作完美!问题我将进入下一页(见上传帖子)。我现在把代码移到了主线程中。从1000 ish跳过帧跳过,现在只跳过34帧。差别很大!!我猜跳过34帧有点正常?
await Task.Run(async () => {
await ssImage.FadeTo(1, 3000);
await ssImage.ScaleTo(1.2, 3000);
});
using Xamarin.Essentials;
...
// Start a background thread, so can delay without pausing `OnAppearing`.
// DO NOT have `await`/`async` here.
Task.Run(() => {
// Give UI thread some time to layout/begin-displaying the page.
// (Without this, a complex page might still be in layout,
// so the animation might start, then hiccup, like the original code.)
Task.Delay(200);
// If UI thread is in middle of displaying the page,
// that is okay; this will run once UI thread is available.
MainThread.BeginInvokeOnMainThread(async () =>
{
// Now we are back on the main thread.
await ssImage.FadeTo(1, 3000);
await ssImage.ScaleTo(1.2, 3000);
});
});