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

Can I freeze the contentOffset while doing layoutWithSpeed? #44

Open
TheoA opened this issue Feb 5, 2013 · 1 comment
Open

Can I freeze the contentOffset while doing layoutWithSpeed? #44

TheoA opened this issue Feb 5, 2013 · 1 comment

Comments

@TheoA
Copy link

TheoA commented Feb 5, 2013

I'm adding/removing items from the MGScrollView, but I'd like to keep the scroll view 'locked' on the currently visible view or equivalent contentOffset while this is happening.

e.g. say I have a scrollView with 10 boxes, each 100px tall, and I'm at contentOffset {0,500} (i.e. I'm scrolled to the 6th box):

I insert another box somewhere at the top of the list:

  [scrollView.boxes insertObject:box atIndex:1];
  [scrollView layoutWithSpeed:1.0 completion:nil];

I want the user to see nothing happen, and contentOffset should now be {0, 600} i.e. adjusted for the new item.

What I've tried:

  • Setting this in the layoutWithSpeed:completion: block. It looks bad because the new item shifts everything down and then it movies back at the end
  • Setting an animation to happen at the same time (both with UIViewAnimationOptionBeginFromCurrentState and without). This doesn't seem to work at all
  • Calling [scrollView layout] in an animation block. This also doesn't seem to work.
@sobri909
Copy link
Owner

sobri909 commented Feb 5, 2013

Interesting problem! My first instinct would be to put it into MGLayoutManager. In the animation block in layoutBoxesIn:withSpeed:completion:, after final positions are set, you then will know the final location of the item in question, and can adjust the offset within the same animation block.

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

No branches or pull requests

2 participants