0

I have a collection view setup with UIKitDynamics Thanks to Here!

I have implemented it in a horizontal scroller and am having some issues with animating scrolls to specify locations in the view. Any scrollTo:Animated: is having trouble it seems.

First, On selection I would like to center those cell. It appears to be jumping back 10-15pts before animating to the correct offset.

Second, while attempting to scroll to a cell and center it horizontally multiple cells away from the current view. It doesn't quite make it all the way there. It is not getting the correct cell centered.

Any help is appreciated, I'm just trying out dynamics and want to learn more. Thanks!

The more problematic issue here is the second. The following sometimes scrolls correctly to index 12, other times it stops short. I would guess that the dynamic animation adjusts the cells in a way that is causing the scroll animation to think the cell is in a different location. That would lead me to believe that the way the attributes for the cell are being returned incorrectly. Again, fairly new to this.

[hCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:12 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];

My code on the ViewController is not doing anything special that would conflict with this.

WCByrne
  • 1,549
  • 1
  • 11
  • 16
  • That's way too vague. You'd really need to show some actual code that people can try out and fix. – matt Mar 01 '14 at 03:00
  • Thought so but wasn't sure where to start. I would assume it must be something in the FlowLayout which I am currently using as is from here. https://github.com/TeehanLax/UICollectionView-Spring-Demo/blob/master/UICollectionView-Spring-Demo/TLSpringFlowLayout.m – WCByrne Mar 01 '14 at 03:16
  • UIKitDynamics with a collection view layout can be pretty tricky stuff. – matt Mar 01 '14 at 03:25
  • Indeed, very cool though. Anymore insight to this issue? – WCByrne Mar 01 '14 at 03:26
  • What I do is override `layoutAttributesForElementsInRect:` so as to get the attributes from the animator, but only if we _are_ animating. – matt Mar 01 '14 at 03:40
  • Rather crude example here: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch08p467collectionViewLayoutFromScratch/ch21p748collectionViewFlowLayout2/MyFlowLayout.m – matt Mar 01 '14 at 03:41
  • Thanks for that. As for the `scrollToItemAtIndexPath:` issue. I'm starting to lean towards bug either in iOS or the example I used. I replaced it with `setContentOffset:` and just calculated it and it is getting to the right spot. – WCByrne Mar 01 '14 at 03:58

0 Answers0