Accelerate sliding or inertial sliding and elastic regression.

Source: Internet
Author: User
I. Preface

In the previous Symbian project, the software interface was completely self-painted. Therefore, the list is also self-painted. Therefore, you need to do the scrolling of the list, and then try to implement two engines:

1. Inertial slide engine: used for long lists, fast slides, and accelerated slides.

2. Auto Regression engine: used for moving the list to the top (end) and moving down (up) to indicate that other tables have arrived.

The engine refreshes every 0.04 seconds (about 24 frames per second). As GC is used for rendering, a rendering function is required for each slide. Efficiency is still not good.

In the past two days, we have transplanted two engines to iOS and found that the effect is not very good. Therefore, direct GC rendering is too inefficient. Because IOS usually uses an offset to achieve the sliding effect.

Ii. algorithm ideas

First, let's talk about the idea of "inertial sliding ".

If the list is long, you can use your hands to move the screen to achieve long sliding. However, this slide is not linear, and there must be some damping effect.

Therefore, for the first time I thought of a parabolic curve, it was derived from the trajectory of the object falling, and it was not good after being tested.

So I thought of the standard normal distribution curve, which has more obvious damping effect. 1:

When a user moves the screen, the initial speed is inevitable when the finger leaves the screen. Then I map the initial speed to the value at the highest point of the Y axis in Figure 1, and then the value decreases over time to simulate the damping sliding effect under natural conditions.

How can we find the initial speed?

Design two arrays with a length of 5, one used to record the coordinate Y value when the user slides. The other one is used to record the time. No matter how long the user slides, only the last five coordinates and five time values are retained. Then, the user's sliding distance is divided by time to calculate the speed. Of course, the unit here is relatively vague (strictly speaking, pixel/microsecond ).

There is also a technical point: if a user slides back and forth on the screen, the track is not a direction. How can this problem be determined. 2:

(Figure 2)

Determine whether the last five points are in the same straight line.

Second, let's talk about the idea of "elastic regression.

In fact, elastic regression is more complex than inertial sliding. Why? This is because I don't need to care about the specific sliding distance when moving inertia. sliding a little more can also be done, just a little less. However, elastic regression is a fixed distance. For example, if the list is pulled down from the top to 100 pixels, then my auto regression engine needs to slide the 100 pixels according to a certain curve within a certain period of time. I chose a parabolic chart this time. The following describes the reasons. As shown in figure 3: 100 pixels indicates the area of the Shadow part in the graph.

(Figure 3)

According to the parabolic arch area formula equal to: with the cut line as the bottom, the tangent point of the same row at the bottom is 3/4 of the inner triangle of the vertex, that is: parabolic Arch area = S + 1/4 * s + 1/16 * s + 1/64 * s + ...... = 4/3 * s

The value of B can be obtained based on the area of the shadow. So, each sliding distance is x1, x2, x3.. X (b-1 ). Here, the area of X1 needs calculus.


All in all: the core of these two engines is two curves for your reference only. This method also allows the company to apply for a patent.

Code I put: http://download.csdn.net/detail/hherima/5161117

Note: This project contains rich text parsing. You only need to checkMylist and browserslideengine. mThat's all.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.