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
An object that manages an ordered collection of data items and presents them using customizable layouts.
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!
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.
A view that defines the behavior for all cells and supplementary views presented by a collection view.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With