[英]Collection View with self sizing cells not scrollable horizontally anymore
I set up a collection view and got all working with fixed height
and width
for the cells. 我设置了一个集合视图,并使所有单元的
height
和width
都固定height
。
Now I would like to have my Cells self sized, so I found that I can add 现在我想让Cells自行调整大小,因此我发现可以添加
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.estimatedItemSize = CGSize(width: 200, height: 50)
menuCollectionView.collectionViewLayout = layout
}
With above code my cell resizes by the width (as wanted), but my collection view is not scrollable horizontally anymore, but instead lays out the cells vertically. 使用上面的代码,我的单元格按宽度调整大小(根据需要),但是我的集合视图不再可以水平滚动,而是垂直地布置单元格。
Is estimatedItemSize
only thought to work for vertical scrolling? 被
estimatedItemSize
只想到为垂直滚动工作? What is wrong with my approach? 我的方法有什么问题?
UICollectionViewFlowLayout的默认滚动方向是垂直的,因此您也需要为新布局设置scrollDirection:
layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.