【发布时间】:2020-02-18 09:45:04
【问题描述】:
我有一个集合视图,其方向设置为水平并启用分页。问题是,我的收藏单元每页的高度有时会高于手机屏幕尺寸。我想要实现的是用户可以向下滚动单元格并向右滑动到下一页。
目前,我只能将集合单元格显示一整页,而无法根据内容高度向下滚动。这里有一些代码:
extension EventListDetailsVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cat = dataArray[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "celldetails", for: indexPath) as? EventListDetailsCVC
cell?.imageEvent.image = UIImage(named: cat.imageEvent)
cell?.eventTitleLabel.text = cat.titleEvent
cell?.eventDescriptionLabel.text = cat.content
return cell!
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: self.collectionView.frame.size.width, height: self.collectionView.frame.size.height)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets.zero
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
}
应该是这样的
我尝试将我的 collectionView 嵌入到 tableView 中,但它似乎不起作用,因为我在单元格中有动态高度。
这是实现这一目标的另一种方式吗?
p/s 我刚开始学 swift,谢谢。
【问题讨论】:
-
尝试在集合视图的单元格中使用表格视图,您可以在表格视图标题中添加您的集合视图单元格,不要实现表格单元格和所有这些
-
@HussainChhatriwala 有道理,稍后再试。
标签: ios swift uicollectionview uiscrollview