dtechの答えは的を射ています。スナップ アニメーションと簡単に組み合わせることができ、x 方向のフリッカブルも簡単に変更できます。また、ユーザーが意図的にフリック可能なものをフリックまたはドラッグしている可能性があります。私の場合、C++ コードは、フリック可能に含まれるグリッド レイアウトのアイテムのテキストまたは表示効果を制御していました。フリック可能なものは、C++ コードがそうするように指示したときにうまくフリックする必要がありましたが、ユーザーが意図的にドラッグまたはフリックした場合はそうではありませんでした。以下は、x 方向のフリック可能に変更された dtech の関数です。
function ensureVisible(item) {
if (moving || dragging)
return;
var xpos = item.mapToItem(contentItem, 0, 0).x
var ext = item.width + xpos
if ( xpos < contentX // begins before
|| xpos > contentX + width // begins after
|| ext < contentX // ends before
|| ext > contentX + width) { // ends after
// don't exceed bounds
var destinationX = Math.max(0, Math.min(xpos - width + item.width, contentWidth - width))
ensureVisAnimation.to = destinationX;
ensureVisAnimation.from = contentX;
ensureVisAnimation.start();
}
}
//This animation is for the ensure-visible feature.
NumberAnimation on contentX {
id: ensureVisAnimation
to: 0 //Dummy value - will be set up when this animation is called.
duration: 300
easing.type: Easing.OutQuad;
}