Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
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
ui.animate()
function. 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.