3

I used UICollectionView and subClassing UICollectionViewLayout to get a circle scrolling view. Code in Custom Layout as below,

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    float minY = CGRectGetMinY(rect);
    float maxY = CGRectGetMaxY(rect);
    int startIndex = fmax(0.0 ,minY / 60);

    int endIndex = fmin([self.collectionView numberOfItemsInSection:0]-1, maxY / 60);
    NSMutableArray* array = [[NSMutableArray alloc]init];
    for( int i = startIndex ;i<=endIndex ;i++)
    {
        NSIndexPath* path = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes* attr = [self layoutAttributesForItemAtIndexPath:path];
        [array addObject:attr];
    }

    return array;
}


- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    float peak = (self.collectionView.contentOffset.y+self.collectionView.frame.size.height/2.0)/60.0;
    float x = 200 - fabs(indexPath.item - peak)*50;
    UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    attr.size = CGSizeMake(250, 50);
    attr.center = CGPointMake(x, indexPath.item*55.0);
    attr.hidden = NO;

    return attr;
}

the initial state misses the 11th cell,but when I scroll, it will appear, why that wired.

Mohd Prophet
  • 1,511
  • 10
  • 17

0 Answers0