PMCircularCollectionView 0.9.1

PMCircularCollectionView 0.9.1

测试测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

Peter Meyers 维护。



  • 作者
  • Peter Meyers

PMCircularCollectionView 是 UICollectionView 的子类,可以在水平和垂直方向上无限滚动。PMCircularCollectionView 还包括一个子类,该子类在滚动后会自动将单元格居中对齐到集合视图的中间。

Demo

要求 & 备注

  • PMCircularCollectionView 是为 iOS 构建的,需要至少 iOS 7 作为最小 iOS 目标。
  • 当前正在对头文件进行彻底的注释。(2014年6月11日)。
  • PMCircularCollectionView 目前缺少单元测试。

如何开始

  • 查看文档(即将推出)。

Podfile

platform :ios, '7.0'
pod "PMCircularCollectionView"

使用

创建 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;

UICollectionViewDataSource

- (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.
    */
}

讨论

  • 为了实现无限滚动,PMCircularCollectionView 采用了一种在 这篇博客文章 中描述的技术,该方法通过乘以内容大小和索引路径的数量来实现。因此,当 dataSource 和 delegate 方法传递一个 item 等于 15 的索引路径时,返回给 -collectionView:numberOfItemsInSection: 代理方法的项数少于 16。如上述示例所示,调用 -normalizeIndex: 将项索引更改为正确的值。
  • -collectionView:numberOfSectionsInCollectionView: 将不会被调用。PMCircularCollectionView 只支持 1 个区域。

创建 PMCenteredCircularCollectionView

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;

PMCenteredCircularCollectionViewDelegate

- (void) collectionView:(PMCenteredCircularCollectionView *)collectionView didCenterItemAtIndex:(NSUInteger)index
{
    NSUInteger normalizedIndex = [collectionView normalizeIndex:index];
    NSLog(@"Collection View: %@\nDid center item at index %d", collectionView, normalizedIndex);
}

通信

  • 如果您 需要帮助,请使用 Stack Overflow。 (标签 'PMCircularCollectionView')
  • 如果您想 提出一个一般性问题,请使用 Stack Overflow
  • 如果您找到了一个错误,请打开一个问题。
  • 如果您有功能请求,请打开一个问题。
  • 如果您想贡献,请提交一个拉取请求。

作者

许可证

PMCircularCollectionView 根据MIT许可证可用。有关更多信息,请参阅LICENSE文件。