我想使用UICollectionView
创建以下视图。我尝试不同的东西将一个项目放在中心,但没有成功。我尝试用滚动确实结束,使它居中,但它有一些奇怪的效果。谁能帮我把这个物品放在中心吗?
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
CGPoint centerPoint = CGPointMake(self.centeredCollectionView.center.x + self.centeredCollectionView.contentOffset.x,
self.centeredCollectionView.center.y + self.centeredCollectionView.contentOffset.y);
NSIndexPath *centerCellIndexPath = [self.centeredCollectionView indexPathForItemAtPoint:centerPoint];
[self.centeredCollectionView scrollToItemAtIndexPath:centerCellIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat widthHeight = collectionView.frame.size.width - 70;
return CGSizeMake(widthHeight, collectionView.frame.size.height);
}