首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >具有动态高度的集合视图水平方向

具有动态高度的集合视图水平方向
EN

Stack Overflow用户
提问于 2020-02-18 09:45:04
回答 2查看 138关注 0票数 0

我有一个集合视图,方向设置为水平和分页启用。事情是,我收集的每页单元格的高度有时都高于手机屏幕的大小。我想要实现的是用户可以向下滚动单元格,然后右转到下一页。

目前,我只能显示一个完整的收集单元格,而不设法根据内容高度向下滚动。这里有一些代码:

代码语言:javascript
运行
复制
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中,但它似乎不起作用,因为我的单元格中有动态高度。

这是另一种方法来实现这一点吗?

我刚开始学得很快,谢谢。

EN

回答 2

Stack Overflow用户

发布于 2020-02-18 09:59:05

您是否尝试过在每个集合视图单元格中嵌入滚动视图?

这将确保集合视图单元格高度不会超过电话高度,而滚动视图将在向下滚动时处理显示更多内容的工作,无论是文本还是图像,还是决定嵌入到滚动视图本身中的任何视图。

票数 1
EN

Stack Overflow用户

发布于 2020-02-18 10:13:10

我认为您应该尝试使用UIPageViewControllerscroll转换风格。它在页面之间有本机分页。

每个页面都应该有UIScrollView。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60277918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档