Berry Blue
Berry Blue

Reputation: 16482

Disable vertical scrolling in UICollectionView programmatically

I have a UICollectionView in a UITableViewCell. The height of the table view cell is set to the height of the collection view so the collection view only scrolls horizontally.

Sometimes when scrolling in the table view the collection view will capture the vertical scrolls and bounce scroll vertically. I've set the height to 0 in -collectionViewContentSize in my custom layout.

How do I completely disable vertical scrolling in a collection view?

Upvotes: 10

Views: 20069

Answers (2)

Henry Noon
Henry Noon

Reputation: 403

To completely disable vertical scrolling in a UICollectionView programatically, add the following to your viewDidLoad() method

self.collectionView.isScrollEnabled = false

Example:

class YourCollectionView: UICollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionView.isScrollEnabled = false
    }
    // Then your methods for creating cells and layout, etc
}

Upvotes: -1

Peter
Peter

Reputation: 1071

In your storyboard - click your UICollectionView and open Utilities. Under the Attributes Inspector, center button, look to 'Bounces'. Uncheck "Bounces Vertically".

Upvotes: 20

Related Questions