You need to enable JavaScript to run this app.
最新活动
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

不一定总是有效的固定UICollectionViewLayout中的interItemSpacing=.fixed(0)

检查UICollectionViewFlowLayout的minimumInteritemSpacingForSectionAt方法的返回值是否为0,并确保在UICollectionViewDelegateFlowLayout协议中实现该方法并返回正确的值。下面是一个示例实现:

class MyCollectionViewFlowLayout: UICollectionViewFlowLayout {
    override func prepare() {
        super.prepare()
        minimumInteritemSpacing = 0
    }

    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        let attributes = super.layoutAttributesForElements(in: rect)
        var leftMargin = sectionInset.left
        var maxY: CGFloat = -1.0
        attributes?.forEach { layoutAttribute in
            if layoutAttribute.frame.origin.y >= maxY || layoutAttribute.frame.origin.x == sectionInset.left {
                leftMargin = sectionInset.left
            }
            layoutAttribute.frame.origin.x = leftMargin
            leftMargin += layoutAttribute.frame.width + minimumInteritemSpacing
            maxY = max(layoutAttribute.frame.maxY , maxY)
        }
        return attributes
    }

    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
        let attribute = super.layoutAttributesForItem(at: indexPath)?.copy() as? UICollectionViewLayoutAttributes
        var leftMargin: CGFloat = sectionInset.left
        if indexPath.row > 0 {
            let previousIndexPath = IndexPath(row: indexPath.row - 1, section: indexPath.section)
            if let previousFrame = layoutAttributesForItem(at: previousIndexPath)?.frame {
                leftMargin = previousFrame.origin.x + previousFrame.width + minimumInteritemSpacing
            }
        }
        attribute?.frame.origin.x = leftMargin
        return attribute
    }

    override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
        return true
    }
}

extension MyViewController: UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
}
本文内容通过AI工具匹配关键字智能整合而成,仅供参考,火山引擎不对内容的真实、准确或完整作任何形式的承诺。如有任何问题或意见,您可以通过联系service@volcengine.com进行反馈,火山引擎收到您的反馈后将及时答复和处理。
展开更多
面向开发者的云福利中心,ECS 60元/年,域名1元起,助力开发者快速在云上构建可靠应用

社区干货

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

不一定总是有效的固定UICollectionViewLayout中的interItemSpacing=.fixed(0) -优选内容

Android SDK集成
红框中的账号 ID 即是 主账号id 3.2 初始化3.2.1 初始化(私有化版本) 首先您需要初始化 Finder SDK,具体可参考:初始化 Finder SDK (私有化版本) - 火山引擎,再初始化资源位 SDK 注意 资源位SDK 要在 Application ... ImageConfig interface 是 配置自定义的图片加载接口,SDK版本 >= 2.1.1 已经废除,无须实现[详细见3.3] uniqueUid string 否 用户画像id,存在用户画像时传入 uniqueUidType string 否 用户画像id类型,存在用户画像...

不一定总是有效的固定UICollectionViewLayout中的interItemSpacing=.fixed(0) -相关内容

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

产品体验

体验中心

云服务器特惠

云服务器
云服务器ECS新人特惠
立即抢购

白皮书

一图详解大模型
浓缩大模型架构,厘清生产和应用链路关系
立即获取

最新活动

爆款1核2G共享型服务器

首年60元,每月仅需5元,限量秒杀
立即抢购

火山引擎增长体验专区

丰富能力激励企业快速增长
查看详情

数据智能VeDI

易用的高性能大数据产品家族
了解详情

一键开启云上增长新空间

立即咨询