UICollectionView does not scroll

I have a UICollectionView with a UICollectionViewDataSource that currently provides six elements. This is less than necessary to fill the screen. The problem is that my view of the collection only scrolls when there are enough elements to fill the screen (checked 10, 20). When displaying fewer elements, it won’t even make this bounce animation that I am trying to get, it’s just fixed.

 - (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; } 

Thanks for your help!

+43
ios iphone uicollectionview
Apr 17 '13 at 20:11
source share
3 answers

bounces , despite this name, is not the right property. You also need to set alwaysBounceVertical and / or alwaysBounceHorizontal . From the documentation:

If this property is set to YES and bounces are set to YES, vertical drag and drop is allowed , even if the content is less than the scroll borders. . The default value is NO.




Note the confusing name in IB .. https://stackoverflow.com>

+149
Jun 06 '13 at 16:16
source share
β€” -

With storyboards in attribute pointers to browse the Bounces and Bounces Vertically collections you should check.

+7
Dec 20 '13 at 12:11
source share

Setting the height of the UICollectionView to UIView will cause your scroll problem to be disabled. If the UICollectionView is 568 pixels high, it will only need to scroll if it contains more than 568 pixels of content. You must set it to the height of the view in which it is contained (as well as the width).

Hope this helps you.

+4
Apr 17 '13 at 20:25
source share



All Articles