0

I have a CListCtrl which has about 100,000+ entries. The user is presented with a search box to search among these entries. On finding a match, I set that as a selection and scroll to it using EnsureVisible.

This scroll happens instantaneously. I wanted to try and code an animation that looks similar to the ones demoed here (especially the 'Go Top - Easing 2' animation).

I'm thinking, for a basic animation,

  1. Get current selection.
  2. Get target selection.
  3. Compute difference.
  4. Get the pixel height of one item.
  5. Mutiply results of step 3 and 4.
  6. Scroll by an increment of 1 (or some other more optimal value) with a delay until increment = result of step 5.

I tried this and I got incredibly confused. Firstly, is my algorithm okay? Secondly, is there another, better way to achieve this (preferably similar to animation 2 in the link above)?

4

1 回答 1

1

Your algorithm seems ok for a simple linear scroll. However your link points to scrolls using various easing functions.

Easing functions do not scroll by the same amount each time, but increase or decrease is order to look like they're speeding up, or slowing down.

A common way to work out easing values is to use the result of a sine. If you picture a sine wave and imagine that you can only see one pixel of it at a time, as the wave progresses, the pixel will "ease" at the extremes and accelerate through the middle values.

Your Easing 2 animation is just adding a bit of bounce at the start and end, this is easily achievable by using the a bit of the sine wave past the extremes at each end. eg.

     _
    / \
   /
\_/

If you want some code, I answered a similar question here in C#.

于 2013-04-19T19:21:04.227 回答