Last active
August 29, 2015 13:56
-
-
Save cbess/8949858 to your computer and use it in GitHub Desktop.
Adjust the position of a UICollectionViewCell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset | |
{ | |
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout*) self.collectionView.collectionViewLayout; | |
// CGFloat maxOffset = (kItemWidth + flowLayout.minimumInteritemSpacing) * kMaxCount; | |
NSInteger item = (targetContentOffset->x / (kItemWidth + flowLayout.minimumInteritemSpacing)); | |
NSIndexPath *targetPath = [NSIndexPath indexPathForItem:item inSection:0]; | |
UICollectionViewLayoutAttributes *attrs = [self.collectionView layoutAttributesForItemAtIndexPath:targetPath]; | |
DebugLog(@"target cell attrs: %@", attrs); | |
// place the offset in front of the cell | |
targetContentOffset->x = CGRectGetMinX(attrs.frame) - flowLayout.minimumInteritemSpacing; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment