【发布时间】:2019-05-25 09:10:12
【问题描述】:
我在添加 UICollectionView 后尝试添加自定义 UIView,因为我想在集合视图上方显示自定义栏视图。这是我的代码:
func loadFilters() {
let categoriesFlowLayout = UICollectionViewFlowLayout()
categoriesFlowLayout.scrollDirection = .vertical
categoriesCollection = UICollectionView(frame: CGRect(x: 10, y: getY(yAxis: searchField) + 10, width: view.frame.size.width - 20, height: (view.frame.size.height * 9 / 10) - getY(yAxis: searchField) - 10), collectionViewLayout: categoriesFlowLayout)
categoriesCollection.register(categoriesCell.self, forCellWithReuseIdentifier: "categoriesCell")
categoriesCollection.delegate = self
categoriesCollection.dataSource = self
categoriesCollection.backgroundColor = UIColor.clear
categoriesCollection.showsVerticalScrollIndicator = false
categoriesCollection.showsHorizontalScrollIndicator = false
view.addSubview(categoriesCollection)
addBar()
categoriesCollection.isUserInteractionEnabled = true
}
addBar() 函数在自定义超类 ViewController 中声明
如果在view.addSubview(categoriesCollection) 之前调用addBar(),它看起来像下图,但如果在之后调用它,那么我的集合视图不会滚动或识别触摸。无论如何都会使集合视图滚动并将自定义栏放在前面?
我也使用过sendSubviewToBack() 和bringSubviewToFront() 函数,但结果是一样的
【问题讨论】:
-
运行您的应用程序并单击调试视图层次结构并检查是否有任何其他视图位于您的集合视图之上
标签: swift