【问题标题】:Centred Paging for CollectionView cells in iOS Objective-CiOS Objective-C 中 CollectionView 单元格的居中分页
【发布时间】:2024-01-20 15:07:02
【问题描述】:

我使用本教程Creating a Scrolling Filmstrip Within a UITableView 创建了一个在其单元格内具有集合视图的表格视图,但我想实现一种横幅类型的功能,该功能具有居中分页并自动滚动到每个单元格项目。我启用了页面滚动,但没有工作。我该怎么做呢?我目前在表格视图单元格中有一个 UIView,用作集合视图的数据源。这是 UIView 子类的代码。

@interface ContainerCellView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) NSArray *collectionData;
@end

@implementation ContainerCellView

#pragma mark - Getter/Setter ovverides
- (void)setCollectionData:(NSArray *)collectionData {
_collectionData = collectionData;
[_collectionView setContentOffset:CGPointZero animated:YES];
[_collectionView reloadData];
} 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}

 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionData count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ArticleCollectionViewCell";
BannersCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *cellData = [self.collectionData objectAtIndex:indexPath.row];
cell.articleTitle.text = [cellData objectForKey:@"title"];
return cell;
 }

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *cellData = [self.collectionData objectAtIndex:indexPath.row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"didSelectItemFromCollectionView" object:cellData];
}
@end

【问题讨论】:

    标签: ios objective-c uitableview uicollectionview


    【解决方案1】:

    您可能正在寻找来自UIScrollView 的名为isPagingEnabled 的collectionView 的属性,否则,您应该创建足够大的单元格来实现这个非常好的效果。
    但是,如果您正在寻找按单元格click here 进行分页,您可以在这里联系

    希望这可以帮助您

    【讨论】: