Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the Example HorizontalGalleryViewController won't save scroll position #93

Open
cylak opened this issue Sep 5, 2018 · 4 comments
Open

Comments

@cylak
Copy link

cylak commented Sep 5, 2018

In the example if you scroll horizontal gallery to left or right and scroll the whole view to down, and back scroll to top again the horizontal gallery back to zero offset.

ArticleExampleViewController, AnimatorExampleViewController and others do the same!

Is there a way for the scroll views (horizontal & vertical) in the HorizontalGalleryViewController to keep their scroll position?

@lkzhao
Copy link
Collaborator

lkzhao commented Sep 6, 2018

if you keep the view in memory then it won’t lose its scroll position. Otherwise you can use scrollViewDidScroll to keep track of the contentOffset for each collectionView

@cylak
Copy link
Author

cylak commented Sep 6, 2018

Thanks. So the CollectionKit doesn’t have any options or settings for keeping scroll position?
How can i use scrollViewDidScroll to keep position? Sorry I’m noob!

@lkzhao
Copy link
Collaborator

lkzhao commented Sep 17, 2018

Yes, you have to implement it your self.
The easiest way is to keep everything in memory and not destroy them.
Another option is, for each collectionView, assign a UIScrollViewDelegate. When scrollViewDidScroll is called, record the contentOffset and send it to your view controller. Use a dictionary in your view controller to track all the contentOffset for each collectionView. and when creating each collectionView, pass the recorded contentOffset on the first reloadData call.

@cylak
Copy link
Author

cylak commented Sep 22, 2018

I'm trying for a few days to implement it, but haven't succeeded yet!
I want to use scrollViewDidScroll. Can you give me a sample code?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants