UICollectionView doesn't bounce when datasource has only 1 item
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?
- indexPathForRowAtPoint returns nil only for first cell in a uitableview
- Detect tap on title of callout
- retrieving stack of ViewControllers when segueing programatically
- iOS swift remove elements of an array from another array
- How to add a UIToolbar to a UITableViewController programmatically?
2 Solutions Collect From Internet About “UICollectionView doesn't bounce when datasource has only 1 item”
UICollectionView has the properties
alwaysBounceVertical. Setting the horizontal to YES
did the trick.
Thanks for @VaporwareWolf ,the answer is correct. I want to add a supplement that:
DO NOT forget setting the
YESat the same time（through storyboard or your code）.
- How to program a delay in Swift 3
- Compile OpenMP programs with gcc compiler on OS X Yosemite
- Converting String to NSDate Giving Wrong Date
- AFNetworking post image in nested json
- Extract Audio from Video AVFoundation
- Getting path for resource in Command Line Tool
- Xcode keeps asking for password to use the System Keychain
- What does the error message “No provisioned iPhone OS device is connected.” mean?
- Drag UIButton without it shifting to center
- iOS: Sample code for simultaneous record and playback
- converting ios 6 app to ios 7
- Different cell size in UICollectionview
- How to run NSTimer in background and sleep in iOS?
- is there a way to tell if an iOS app is closed unexpectedly?(crash, force close)
- Screenshot showing up blank – Swift