У меня есть UICollectionView, длина которого больше ширины экрана, и поэтому я хотел бы включить прокрутку, чтобы пользователь мог ее видеть. К сожалению, вызов setScrollEnabled: YES, похоже, ничего не делает.
// CODE TO SET UP
UICollectionView *tabLayerCollectionView;
UICollectionViewFlowLayout *flowLayout;
// Dont want any space between cells
flowLayout.minimumInteritemSpacing = 0; // Scrolling works if we have a space inbetween cells, but spaces are not desired.
flowLayout.minimumLineSpacing = 0;
tabLayerCollectionView = [[UICollectionView alloc]
initWithFrame:CGRectMake(0, 40, widthOfTabLayer, noteHeight)
collectionViewLayout:flowLayout];
// HERE - scrolling not working
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[tabLayerCollectionView setScrollEnabled:YES];
[tabLayerCollectionView setDataSource:self];
[tabLayerCollectionView setDelegate:self]; // See below for completness
[tabLayerCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:myIdentifier];
[tabLayerCollectionView setBackgroundColor:[UIColor clearColor]];
//NSLog(@"DrumKitViewController tabList count:%i",(int)tabList.count);
[self.view addSubview:tabLayerCollectionView];
[tabLayerCollectionView reloadData];
// TAB LAYER INHERITED METHODS For Completeness
// Called once
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSLog(@"numberOfItemsInSection called Tablist count:%i",(int)tabList.count);
return tabList.count;
}
// The cell that is returned must be retrieved from a call to dequeueReusableCellWithReuseIdentifier:forIndexPath:
// Called for each indexPath row (after all layout called
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"collectionView collectionView called index section:%i row:%i",(int)indexPath.section,(int)indexPath.row);
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:myIdentifier forIndexPath:indexPath];
NSMutableArray *clickList = [tabList objectAtIndex:indexPath.row];
// Background (Not at start or end)
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, noteWidth, noteHeight)];
[backgroundImageView setImage:[UIImage imageNamed:@"bg_middle.png"]];
[cell setBackgroundView:backgroundImageView];
for (NSString *drumTabItem in clickList){
//NSLog(@"clickList.count:%i drumTabItem:%@",(int)clickList.count,drumTabItem);
// Get drumTabItem and add to itemImageView
UIImageView *tabItemImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, noteWidth, noteHeight)];
tabItemImageView.image = [UIImage imageNamed:drumTabItem];
[cell.contentView addSubview:tabItemImageView];
}
return cell;
}
// Called for each indexPath row
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0){
// This has the timing, so make bigger
widthOfTimeComponent = noteWidth*2;
return CGSizeMake(noteWidth*2, noteHeight); // Gives more white space
}
else {
NSMutableArray *clickList = [tabList objectAtIndex:indexPath.row];
for (NSString *item in clickList){
if ([item isEqualToString:@"bg_middle.png"]){
//NSLog(@"EMPTY found at indexRow:%i noOfRows:",(int)indexPath.row);
if (countNonEmptyItems > 32.0){
//widthOfTabLayer = widthOfTabLayer + (noteWidth/6);
return CGSizeMake(noteWidth/6, noteHeight); // Needs to be shorter
}
else if (countNonEmptyItems > 24.0){
//widthOfTabLayer = widthOfTabLayer + (noteWidth/4);
return CGSizeMake(noteWidth/4, noteHeight); // Needs to be shorter
}
else if(countNonEmptyItems > 15.0){
//widthOfTabLayer = widthOfTabLayer + (noteWidth/3);
return CGSizeMake(noteWidth/3, noteHeight); // Needs to be wider
}
else if(countNonEmptyItems > 10.0){
//widthOfTabLayer = widthOfTabLayer + (noteWidth/2);
return CGSizeMake(noteWidth/2, noteHeight); // Needs to be wider
}
else{
return CGSizeMake(noteWidth, noteHeight); // 30x165 (
}
}
else{
return CGSizeMake(noteWidth, noteHeight); // 30x165
}
}
}
// Shouldn't get here
return CGSizeMake(noteWidth, noteHeight); // 30x165
}
Я предполагал, что setScrollEnabled: YES включит прокрутку. Любая причина, почему это не работает?