开发者

How does a UIScrollView scroll so well even with a flicky/jerky motion?

For experimentation I've got a UIViewCont开发者_Python百科roller and a custom window that intercepts touch events, so that I can drag and flick different UIViews around the screen. There are 3 event types that I handle: UITouchPhaseBegan and UITouchPhaseMoving (where I simply move the sub-UIView according to the touch coordinate) and UITouchPhaseEnded (where I apply a force to the UIView to get it to move across the screen, slowing down with friction).

The way I calculate the force to be applied when ending a touch event is by calculating the direction vector between the last (from UITouchPhaseMoving) and current (from UITouchPhaseEnded) touch locations, however it doesn't seem to be giving me the results I want.

When I move the view and lift my finger off the screen smoothly it moves nicely, however when I "jerk" the motion towards the end it doesn't move as far as expected. This is because even though I move it across the screen for a few frames, the jerking motion at the end makes the coordinates of the last and current touch events too close, so I don't get the full force calculated.

Sorry for the long text, but I noticed that views such as UIScrollView still scroll properly even with this jerky/flicky motion; is this because the final force is calculated over a number of frames, rather than just the last and current frames? If so, does anybody know the inner workings of the scrollview that allow it to work so well even with a flicky/jerky motion?


I dont know the inner workings, but suspect it calculates a force vector by taking the touch down coordinates and time, and the release coordinates and time. once it has this, applying a deceleration to it, for inertia. I think this could be something that is very difficult to get right, and apple have spent a long time fine tuning this, even down to the speed of the bounce when it reaches its bounds. Definitely an interesting experiment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜