PMCircularCollectionView 是 UICollectionView 的子类,可以在水平和垂直方向上无限滚动。PMCircularCollectionView 还包括一个子类,该子类在滚动后会自动将单元格居中对齐到集合视图的中间。
platform :ios, '7.0'
pod "PMCircularCollectionView"
PMCenteredCollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 0;
PMCenteredCircularCollectionView *collectionView = [PMCircularCollectionView collectionViewWithFrame:self.view.bounds collectionViewLayout:layout];
collectionView.delegate = self;
collectionView.dataSource = self;
- (UICollectionViewCell *) collectionView:(PMCenteredCircularCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PMCellReuseIdentifier forIndexPath:indexPath];
NSInteger normalizedIndex = [collectionView normalizeIndex:indexPath.item];
/*
* Configure cell based on indexPath.section and normalizedIndex.
*/
}
PMCenteredCollectionViewFlowLayout *layout = [PMCenteredCollectionViewFlowLayout new];
layout.centeringDisabled = NO;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 0;
PMCenteredCircularCollectionView *collectionView = [PMCenteredCircularCollectionView collectionViewWithFrame:self.view.bounds collectionViewLayout:layout];
collectionView.delegate = self;
collectionView.dataSource = self;
- (void) collectionView:(PMCenteredCircularCollectionView *)collectionView didCenterItemAtIndex:(NSUInteger)index
{
NSUInteger normalizedIndex = [collectionView normalizeIndex:index];
NSLog(@"Collection View: %@\nDid center item at index %d", collectionView, normalizedIndex);
}
PMCircularCollectionView 根据MIT许可证可用。有关更多信息,请参阅LICENSE文件。