UICollectionView doesn't bounce when datasource has only 1 item
Asked Answered
S

2

55

I have a UICollectionView with a custom UICollectionViewFlowLayout. It scrolls horizontally and only shows one item at a time (full height). I have pagingEnabled = YES so that it sticks to pages.

The UICollectionView shows photos within a particular day. I initially had buttons to change the day +/- 1 day, but I thought it would be neat if the user could pull on the collection view past the first or last image (past a predetermined threshold) to change the day. I implemented this using the UIScrollView delegate methods and it works great...... if there are 2 or more items in the collection view.

This is hard to describe, but if there is only 1 item, it doesn't allow me to pull the item past it's bounds. I.E. there is no bounce to it.

I'd like to have this behavior, but I need to overcome this problem first. I'm thinking that if I removed pagingEnabled = YES and used targetContentOffsetForProposedContentOffset:proposedContentOffset:withScrollingVelocity, that I may be able to get it to work but I really enjoy the snappy behavior that paging enables. (They are mutually exclusive).

Any ideas on this?

Sumter answered 22/8, 2013 at 21:15 Comment(0)
S
137

UICollectionView has the properties alwaysBounceHorizontal and alwaysBounceVertical. Setting the horizontal to YES did the trick.

Sumter answered 22/8, 2013 at 21:19 Comment(4)
To enable this inside the Interface Builder — use the option called "Bounce Vertically".Terricolous
alwaysBounceHorizontal and alwaysBounceVertical are originated from view UIScrollView.Anacardiaceous
So can I say that UITableView has this property set to YES as default since it can be bounds?Channelize
For me assigning layout instance in viewDidLayoutSubviews was the issue.Joost
M
5

Thanks for @VaporwareWolf ,the answer is correct. I want to add a supplement that:

DO NOT forget setting the bounces property to YES at the same time(through storyboard or your code).

Mesenchyme answered 13/12, 2016 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.