0

I want my UICollectionView to automatically scroll to the bottom. I have this code in my viewDidAppear but when I run it, there is always an half-second pause between the view is showed and the collection view is scrolled to the bottom. I read other questions and didn't find an answer yet. Anyone has an idea?

- (void)viewDidAppear:(BOOL)animated{

    NSInteger numbersOfItems = self.photoAssets.count - 1;
    NSLog(@"%i", [self.collectionView numberOfItemsInSection:0]);
    [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:numbersOfItems inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];

}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
BalestraPatrick
  • 9,944
  • 4
  • 30
  • 43

2 Answers2

1

Are your cells fast to init? What may be happening is visible cells (at top) are getting created, then some additional ones have to get created, and it's slowing down the perceived time to scroll. You may want to reduce their complexity, and/or scroll to the items as soon as they are loaded into the collection view instead of waiting for viewDidAppear.

akaru
  • 6,299
  • 9
  • 63
  • 102
  • Thanks! Scrolling to items as soon as they are loaded in `collectionView:cellForItemAtIndexPath:` worked for me. – ken Sep 25 '14 at 05:29
0

Have you tried calling this code in i.e viewDidLoad?

NSInteger numbersOfItems = self.photoAssets.count - 1;
NSLog(@"%i", [self.collectionView numberOfItemsInSection:0]);
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:numbersOfItems inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];

Take a look at this guide for more information about the view load process

Community
  • 1
  • 1
Paroxysm
  • 26
  • 1