我使用UICollectionView
和subClassing UICollectionViewLayout
来获取圆形滚动视图。自定义布局中的代码如下所示,
- (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;
}
初始状态错过了第11个cell
,但是当我滚动时,它会出现,为什么连线。