MGBoxKit icon indicating copy to clipboard operation
MGBoxKit copied to clipboard

Can I freeze the contentOffset while doing layoutWithSpeed?

Open TheoA opened this issue 12 years ago • 1 comments

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.

TheoA avatar Feb 05 '13 14:02 TheoA

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.

sobri909 avatar Feb 05 '13 14:02 sobri909