与标题重叠的不可开发的 CollectionViewCells [Swift]
Posted
技术标签:
【中文标题】与标题重叠的不可开发的 CollectionViewCells [Swift]【英文标题】:Untappable CollectionViewCells Which Overlaps Header [Swift] 【发布时间】:2020-11-23 03:48:05 【问题描述】:如标题所述,实际上我对点击区域有疑问。我所做的是使用自定义UICollectionViewFlowLayout
中的SectionInset
将单元格与标题重叠,因此它看起来像图片上所述。
问题是,你可以看到那里的红色圆圈和绿色圆圈,它代表不能点击,可以点击。我已经搜索了一整天,但没有找到答案。
我有什么遗漏的吗?
ViewDidLoad
中的单元格插入代码:
let layout: FlowLayoutProperty = FlowLayoutProperty.init(itemSize: CGSize.zero, minimumInteritemSpacing: 10, minimumLineSpacing: 10)
layout.scrollDirection = UICollectionView.ScrollDirection.vertical
layout.sectionInset = UIEdgeInsets.init(top: -50, left: 10, bottom: 10, right: 10)
标题代码为:
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
//header height size, refer headerreferencesize
switch kind
case UICollectionView.elementKindSectionHeader:
guard let headerView: V4UMGCMainHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "V4UMGCMainHeaderWeather", for: indexPath) as? V4UMGCMainHeader else
fatalError("Header not found")
self.headerView = headerView
let dFormat: DateFormatter = DateFormatter.init()
dFormat.dateFormat = "EE, dd MMM"
headerView.lblUMGCWDate.text = dFormat.string(from: Date.init())
headerView.btnUMGCWAddMember.transformToContentStandard()
headerView.btnUMGCWAddMember.titleLabel?.font = FontPredefine.MuliMedium(withSize: 12.0)
headerView.btnUMGCWAddMember.backgroundColor = UIColor.hexStringToUIColor(hex: "#C18845")
headerView.btnUMGCWAddMember.addTarget(self, action: #selector(self.checkMemberShipHeader(sender:)), for: UIControl.Event.touchUpInside)
headerView.lblUMGCWLocation.text = "Point Location"
if(KeychainedLoginCache.loadClubMemberInfo()[.ClubHouseID]! == nil && self.menuType == MenuType.UserMode)
//if clubmember not available
headerView.btnUMGCWAddMember.setTitle(AppDelegate.getLocalString(forKey: "UMGCVC_CLUBHEADER_ADDMEMBER_BTN"), for: UIControl.State.normal)
headerView.btnUMGCWAddMember.isEnabled = true
headerView.lcUMGCWAddMemberHeight.constant = 40
self.headerLayoutProperty?.sectionInset = UIEdgeInsets.init(top: -50, left: 10, bottom: 10, right: 10)
else
//if clubmember available
headerView.btnUMGCWAddMember.setTitle("", for: UIControl.State.normal)
headerView.btnUMGCWAddMember.isEnabled = false
headerView.lcUMGCWAddMemberHeight.constant = 0
self.headerLayoutProperty?.sectionInset = UIEdgeInsets.init(top: -90, left: 10, bottom: 10, right: 10)
return headerView
default:
assert(false, "error")
return V4UMGCMainHeader.init()
【问题讨论】:
【参考方案1】:好的,我认为这真的很棘手。我应该把zIndex
放在UICollectionViewFlowLayout
下layoutAttributesForElements
和layoutAttributesForItem
下,现在可以了。
【讨论】:
以上是关于与标题重叠的不可开发的 CollectionViewCells [Swift]的主要内容,如果未能解决你的问题,请参考以下文章
使用 UISearchController 时,iOS 13 UIBarButtonItem 不可点击和重叠 UINavigationBars