我试图制作一个水平滚动的1 x N UICollectionView
但是垂直锁定所以它根本不会垂直移动。
有关如何实现这一目标的任何想法或指示?
答案 0 :(得分:20)
使用流布局,并将滚动方向属性设置为水平。
文档here。
答案 1 :(得分:7)
使用流程布局并将滚动方向设置为水平以解决问题。
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: UIScreen.main.bounds.width/2 - 10, height: 190)
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
flowLayout.scrollDirection = .horizontal
flowLayout.minimumInteritemSpacing = 0.0
mainHomeCollectionView.collectionViewLayout = flowLayout
答案 2 :(得分:-1)
Swift 3
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: UIScreen.main.bounds.width/2-10, height: 190)
flowLayout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5)
flowLayout.scrollDirection = UICollectionViewScrollDirection.horizontal
flowLayout.minimumInteritemSpacing = 0.0
mainCollectionView.collectionViewLayout = flowLayout