UICollectionView cell overlapping with Header

与世无争的帅哥 提交于 2020-01-15 10:27:25

问题


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let collectionViewWidth = collectionView.bounds.width


        let keys = Array(indoordataDictionary.keys)
        let keyString:String = keys[indexPath.section]
        let objFacilityUserList:FacilityUserList = indoordataDictionary[keyString]! as! FacilityUserList

        if objFacilityUserList.facilityUserList.count == 1 {
            return CGSize(width: collectionViewWidth, height: 30)
        }
    return CGSize(width: collectionViewWidth/2, height: 70)
}


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 5
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {

    if indoorSegment.selectedSegmentIndex == 1 {
        return CGSize(width:collectionView.frame.size.width, height:0.0)
    }
    else {
        return CGSize(width:collectionView.frame.size.width, height:40.0)
    }
}


func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

    let headerView: PlaceCollectionReusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: TagIDConstant.nibs.kPlaceCollectionReusableViewID, for: indexPath) as! PlaceCollectionReusableView
    let keys = Array(indoordataDictionary.keys)
    let keyString:String = keys[indexPath.section]
    headerView.placeNameLabel.text = keyString

    return headerView
}

回答1:


If you are using the Custom Layout for the CollectionView then the following link is the best class for that, which will solve this Section Header overlapping problem.

https://gist.github.com/olxios/9e0ae85d49529b0d8b8a6fe6e7a00fab

Hope it helps to those who are using the Custom Layout for the CollectionView.



来源:https://stackoverflow.com/questions/49359422/uicollectionview-cell-overlapping-with-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!