举手优化
This commit is contained in:
parent
cb5286163c
commit
902c2991ec
@ -24,6 +24,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
private const double CardHeight = 534;
|
||||
private const double CardGap = 30; // 卡片之间水平间距
|
||||
private const double SlideDurationMs = 380; // 动画时长
|
||||
private const double ProgressDurationMs = 2600;
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
@ -65,6 +66,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
private EventHandler? _renderHandler;
|
||||
|
||||
private CoverFlowItem? _currentItem;
|
||||
private DateTime _progressStartTime;
|
||||
|
||||
private void CoverFlowControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@ -97,7 +99,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
var current = Images[SelectedIndex];
|
||||
|
||||
// 停止动画/计时
|
||||
StopProgress();
|
||||
StopProgress(resetProgress: true);
|
||||
|
||||
// 清零当前的进度值
|
||||
current.Progress = 0;
|
||||
@ -105,29 +107,33 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
}
|
||||
public void StartProgress(CoverFlowItem item)
|
||||
{
|
||||
StopProgress();
|
||||
StopProgress(resetProgress: true);
|
||||
|
||||
_currentItem = item;
|
||||
item.Progress = 0;
|
||||
_progressStartTime = DateTime.UtcNow;
|
||||
|
||||
_renderHandler = (s, e) =>
|
||||
{
|
||||
if (_currentItem.Progress < 1)
|
||||
{
|
||||
_currentItem.Progress += 0.007; // 控制速度
|
||||
}
|
||||
else
|
||||
if (_currentItem == null)
|
||||
return;
|
||||
|
||||
var elapsedMs = (DateTime.UtcNow - _progressStartTime).TotalMilliseconds;
|
||||
_currentItem.Progress = Math.Min(1, elapsedMs / ProgressDurationMs);
|
||||
|
||||
if (_currentItem.Progress >= 1)
|
||||
{
|
||||
_currentItem.Progress = 1;
|
||||
ProgressCompleted?.Invoke(_currentItem);
|
||||
// 停止动画
|
||||
StopProgress();
|
||||
StopProgress(resetProgress: false);
|
||||
}
|
||||
};
|
||||
|
||||
CompositionTarget.Rendering += _renderHandler;
|
||||
}
|
||||
|
||||
private void StopProgress()
|
||||
private void StopProgress(bool resetProgress = true)
|
||||
|
||||
{
|
||||
if (_renderHandler != null)
|
||||
@ -138,7 +144,9 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
|
||||
if (_currentItem != null)
|
||||
{
|
||||
_currentItem.Progress = 0;
|
||||
if (resetProgress)
|
||||
_currentItem.Progress = 0;
|
||||
|
||||
_currentItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user