iOS touch scroll algorithm?

Hi, I want to create something similar to tableView in iOS.

It is easy to make it follow the touch move action by calculating touch.y but I don’t know how to make it smoothly slide then stop after touchUp.

Is there any addon for doing this kind of thing? or can someone please tell me how to achieve this?

don’t know if there’s an addon doing just this, but i wrote a scroll panel as part of the ofxMightyUI library. relevant code is here: https://github.com/kritzikratzi/ofxMightyUI/blob/master/src/ScrollPane.cpp

what’s tricky about it is that there are different kinds of animations, not just one.
there are momentum animations when you flick your finger and let go, then watch it decelerate. but then there’s also animations when going to a specific page, or when you scrolled below the edge of the page.

i remember it was much more complicated than i had guessed. i can’t recall the exact page, but i followed the analysis that other people had already done, something like this: http://ariya.ofilabs.com/2011/10/flick-list-with-its-momentum-scrolling-and-deceleration.html just look at the first image. it gives a good overview of how the scrolling works.

2 Likes

Thank you very much I will try that today :smiley:

Hi @cuinjune i’m stating to do something similar how was you experince?,can you give me some adivices to start? Thanks.

Hi @lkkd I personally found this post very helpful.

It’s written in Javascript but the code is pretty straightforward so it wasn’t too difficult to rewrite the code in C++. Based on this, I could create a tableView-like UI for my iOS app.

I could just share my code here but it is currently difficult for me to separate out the relevant code from my app so I’d rather suggest you creating one yourself.

After following the tutorial, you may want to customise your UI further if you want features like edge bounce or elastic effect. I can’t remember if there was any good tutorial resource about these effects.

1 Like

@cuinjune Aweseome! Thanks.
I will take a look.

Hi, i read the tutorial very interesting i understand what’s going on and i think i can rewrite it in c++ most of the code already start but i only have a doubt about the event listeners can you give me a hand with this? i also think that would be nice to make an addon from it, is something very basic in iOS apps will save a lot of time for future devopers. Thanks.

I didn’t create any event listener myself. I didn’t even make it as a separate class but just implemented it straight onto ofApp.cpp file. The implementation exists in update(), draw() and touchEvent listeners. I wasn’t really experienced back then so the code is really messy and needs to be cleaned in order to be shared. That’s why I suggested you creating one yourself. I’m sure you can implement it in a much better and cleaner way than I did. I agree that it would be nice to make it as an addon for future devs but I will have to almost completely re-write the code anyway and I’m afraid I can’t afford the time to do it at the moment as I’m currently working on other stuff. I hope you understand me. :slight_smile:

Is fine, i feel you. I’m also in rush but i try to make a clean code and try to make the addon.