我正在使用故事板动画来开发我的Windows Phone 8.1应用程序,但有时会出现严重的卡顿问题。(Lumia 930) 噢,还有,我想我可以补充一下,这是一个通用应用程序模板。
首先是动画代码:
<Page.Resources>
<local:SimpleMathConverter x:Key="SimpleMathConverter"/>
<Storyboard x:Name="ImageViewShowAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="GameImageView">
<EasingDoubleKeyFrame KeyTime="0" Value="90"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="ImageViewHideAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="GameImageView">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="90"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="ResultViewShowAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="GameResutView">
<EasingDoubleKeyFrame KeyTime="0" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="ResultViewHideAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="GameResutView">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="-90"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Page.Resources>
接下来是代码后端事件处理
public GamePage()
{
ImageViewHideAnimation.Completed += (sender, o) => ResultViewShowAnimation.Begin();
ResultViewHideAnimation.Completed += (sender, o) => ImageViewShowAnimation.Begin();
}
以及触发动画的按钮
private async void ChangeState()
{
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
switch (state)
{
case GameState.ImageView:
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ImageViewHideAnimation.Begin());
state = GameState.ResultView;
break;
case GameState.ResultView:
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ResultViewHideAnimation.Begin());
state = GameState.ImageView;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
这个动画的作用是模拟翻转一张卡片并显示其背面内容,当您再次点击旋转按钮时,它会再次翻转卡片并显示初始内容。问题在于有时候(我会说4/10的情况下),当动画应该开始并且实际上已经开始时,它会出现卡顿,并且只显示了动画的一半。就像动画已经开始但屏幕还没有跟上来一样。我尝试使用和不使用dispatcher运行动画,希望能产生其他效果,但都没有成功。您有什么建议可以解决这个问题吗?