我在 Behavior 中有一个动画,但它运行不流畅。
这是我的动画代码:
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
animation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(0).(1)", UIElement.RenderTransformProperty, RotateTransform.AngleProperty));
int keyFrameCount = 16;
double timeOffsetInSeconds = 0.1;
int targetValue = 12;
double totalAnimationLength = keyFrameCount * timeOffsetInSeconds;
double repeatInterval = RepeatInterval;
bool isShaking = IsShaking;
// Can't be less than zero and pointless to be less than total length
if (repeatInterval < totalAnimationLength)
repeatInterval = totalAnimationLength;
animation.Duration = new Duration(TimeSpan.FromSeconds(repeatInterval));
for (int i = 0; i < keyFrameCount; i++)
{
animation.KeyFrames.Add(new LinearDoubleKeyFrame(i % 2 == 0 ? targetValue : -targetValue, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds))));
}
animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(totalAnimationLength))));
但是,如果我选择
int keyFrameCount = 360;
和
for (int i = 0; i < keyFrameCount; i++)
{
animation.KeyFrames.Add(new LinearDoubleKeyFrame(i, keyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds))));
}
它会旋转一个非常平滑的圆圈。
我怎样才能让动画从 0 度到 30 度,回到 -30 度,然后回到 0(让它稍微抖动一下)并让它看起来流畅。
经过一些尝试,我发现(正常)来回在这里不起作用,它的行为完全不受控制!