In addition to Fogmeister's answer (with code), the cleanest approach is to invert (flip) a UICollectionView so that you have a scroll view that sticks to the bottom, not the top. This also works for a UITableView , as Fogmeister points out.
- (void)viewDidLoad { [super viewDidLoad]; self.collectionView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0); }
In Swift:
override func viewDidLoad() { super.viewDidLoad() collectionView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0) }
This has the side effect of also displaying your cells upside down, so you should also flip them. Therefore, we pass trasform ( cell.transform = collectionView.transform ) as follows:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.transform = collectionView.transform; return cell; }
In Swift:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! UICollectionViewCell cell.transform = collectionView.transform return cell }
Finally, the main thing to remember when developing as part of this project is that the NSIndexPath parameters in the NSIndexPath delegates NSIndexPath reversed. Thus, indexPath.row == 0 is the line at the bottom of the collectionView where it is usually at the top.
This method is used in many open source projects to create the described behavior, including the popular SlackTextViewController ( https://github.com/slackhq/SlackTextViewController ) supported by Slack
I think I would add some code to Fogmeister's fantastic answer!