Animate content offset
I am not having much luck animating content offset. When the view loads I want the scrollview to glide to the offset position. Any tips implementing the
import ui w, h = ui.get_screen_size() sv = ui.ScrollView() sv.frame = (0,0,w,h) sv.background_color = 'gray' sv.content_size = (0, 2000) y_offset = 1000 sv.present() sv.content_offset = (0, y_offset) #animate me
Something like this should work:
# ... def scroll(): sv.content_offset = (0, y_offset) ui.animate(scroll, 0.5)
Great thanks. Now I get it.
Alternative, if you don't like nested functions:
from functools import partial ui.animate(partial(setattr, sv, 'content_offset', (0, y_offset)), 0.5)
(I find this a bit harder to read though.)
Oooo. Cleaver. That is definitely for the pros. I like it.
iirc lambdas also work, and might be slightly easier to read than partial.