【发布时间】:2022-06-15 01:48:27
【问题描述】:
我需要禁止选择集合视图,但启用了 CV 的标题?
这两种方法都阻塞了头部。如何开启?
CollectionView.isUserInteractionEnabled = false
或
CollectionView.allowsSelection = false
这里是 UICollectionReusableView:
final class HeaderCollectionReusableView: UICollectionReusableView {
override init(frame: CGRect) {
super.init(frame: .zero)
addSubView()
setupLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
static let headerIdentifier = "HeaderCollectionReusableView"
private func addSubView() {
addSubview(collectionView)
}
public lazy var collectionView: UICollectionView = {
var flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .horizontal
flowLayout.itemSize = CGSize(width: UIScreen.main.bounds.size.width / 3.5, height: UIScreen.main.bounds.size.width / 3)
flowLayout.minimumLineSpacing = 12
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
var view = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
view.register(cell: CollectionViewCell.self)
view.backgroundColor = .clear
view.showsHorizontalScrollIndicator = false
view.showsVerticalScrollIndicator = false
view.contentInsetAdjustmentBehavior = .automatic
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private func setupLayout() {
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: topAnchor),
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
collectionView.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.width / 3),
])
}
}
这是嵌入在其他垂直 CV 标题中的水平 CV。 我需要禁用垂直 CV,但在垂直 CV' 标题中启用水平 CV)
【问题讨论】:
-
请分享您的标题视图代码。
-
@Asteroid 代码共享)
-
您不能禁用集合视图上的用户交互并仅为您有权访问的标题视图启用它吗? developer.apple.com/documentation/uikit/uitableview/…
-
@cora I cant ) 我禁用了 CV 用户交互,并且它的标题也禁用了。
-
您是否尝试为每个单元格禁用(在单元格 For Row 中)?
标签: ios swift selection collectionview disable