简体   繁体   中英

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?

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

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM