我正在开发具有动量面板(用于平滑滚动)的移动应用程序 UI,我目前正在使用以下代码在平滑滚动期间更新 UI:
private void scrollKinetic()
{
while (_curState == States.KineticScroll)
{
// This gets how far the panel will move with the current velocity, then updates the velocity according to the current friction.
var distY = GetDistance(scrVelocity.Y);
var distX = GetDistance(scrVelocity.X);
if (distY + distX <= 0) // Friction will eventually make distX and distY both 0
{
_curState = States.Idle;
Invalidate();
break;
}
// CalculatePosition will move the panel accordingly.
CalculatePosition(distY, scrVelocity.Y, false);
CalculatePosition(distX, scrVelocity.X, true);
Invalidate();
friction++;
Application.DoEvents();
}
}
如您所见,Application.DoEvents();
正在抬起丑陋的脑袋!我想摆脱它,但我想不出任何方法来循环和更新 UI。任何帮助/想法都会很棒!
我在.net CF 上这样做,但我认为这是一个设计问题,所以我认为平台不会太重要。