我有一个集合视图,方向设置为水平和分页启用。事情是,我收集的每页单元格的高度有时都高于手机屏幕的大小。我想要实现的是用户可以向下滚动单元格,然后右转到下一页。
目前,我只能显示一个完整的收集单元格,而不设法根据内容高度向下滚动。这里有一些代码:
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中,但它似乎不起作用,因为我的单元格中有动态高度。
这是另一种方法来实现这一点吗?
我刚开始学得很快,谢谢。
发布于 2020-02-18 09:59:05
您是否尝试过在每个集合视图单元格中嵌入滚动视图?
这将确保集合视图单元格高度不会超过电话高度,而滚动视图将在向下滚动时处理显示更多内容的工作,无论是文本还是图像,还是决定嵌入到滚动视图本身中的任何视图。
发布于 2020-02-18 10:13:10
我认为您应该尝试使用UIPageViewController的scroll转换风格。它在页面之间有本机分页。
每个页面都应该有UIScrollView。
https://stackoverflow.com/questions/60277918
复制相似问题