Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When did `UICollectionView` come to an end

Im using a UICollectionView and using a UIButton to scroll from cell to cell. I want the button.hidden = YES when I come to the end of the collection view. How do I know when currentIndex == MAX

like image 883
000 Avatar asked Feb 23 '15 09:02

000


People also ask

What is a UICollectionView?

An object that manages an ordered collection of data items and presents them using customizable layouts.

How does UICollectionView work?

UICollectionView makes adding custom layouts and layout transitions, like those in Photos, simple to build. You're not limited to stacks and grids because collection views are customizable. You can use them to make circle layouts, cover-flow style layouts, Pulse news style layouts and almost anything you can dream up!

How does swift implement UICollectionView?

Select the Main storyboard from the file browser. Add a CollectionView by pressing command shift L to open the storyboard widget window. Drag the collectionView onto the main view controller. Add constraints to the UICollectionView widget to ensure that the widget fills the screen on all devices.

What is UICollectionReusableView?

A view that defines the behavior for all cells and supplementary views presented by a collection view.


1 Answers

A collection view is a scroll view. You therefore have access to all of the scroll view delegate methods - scrollViewDidScroll: will be called every time the scroll view moves, you can check at that point if you've scrolled to the bottom, or end, or wherever.

Note that the contentOffset property will refer to the origin of the visible scroll area, so it's probably simplest to check something like this:

if (CGRectGetMaxY(scrollView.bounds) == scrollView.contentSize.height) {
    button.hidden = YES;
}

This delegate method would not be called if you scrolled the view yourself, however - it would only apply if the view was scrolled by the user. You'd need to either call this yourself at the end of your automatic scrolling code or have similar logic in your automatic scrolling code to check this yourself.

like image 98
jrturton Avatar answered Sep 19 '22 06:09

jrturton