UICollectionView
은 현재 6 개 항목을 제공하는 UICollectionViewDataSource
으로 설정되어 있습니다. 화면 채우기에 필요한 것보다 적습니다. 문제는 화면을 채울 수있는 항목이 충분할 때만 (10, 20으로 테스트 한 경우) 컬렉션보기가 스크롤된다는 것입니다. 더 적은 수의 아이템을 표시 할 때, 나는이 바운스 애니메이션을 얻지 못할 것입니다.UICollectionView가 스크롤되지 않습니다.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCollectionViewData) name:UIDocumentStateChangedNotification object:nil];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.itemSize = CGSizeMake(160, 100);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.bounces = YES;
[self.view addSubview:self.collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionViewData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Expense *expense = [self.collectionViewData objectAtIndex:indexPath.row];
UILabel *label = [[UILabel alloc]initWithFrame:cell.bounds];
label.text = expense.value;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"Miso-Bold" size:30];
label.textAlignment = NSTextAlignmentCenter;
[cell addSubview:label];
cell.backgroundColor = [UIColor colorWithRed:1 - (indexPath.row/30.0f) green:0 blue:1 alpha:1];
return cell;
}
도움 주셔서 감사합니다.
이것은 올바른 대답입니다. OP는 이것을 대답으로 받아 들여야합니다. –
위대한 팁 감사합니다 – Fattie
고마워요, 그것은 매력처럼 작동합니다 :) – evya