Ios 在另一个视图中插入contentView将使单元格接触无效
我试图在UICollectionViewCell中的单元格内容后面添加滚动视图。然而,一旦我添加了它,我就选择了Cell。。。不再工作了。有什么想法吗Ios 在另一个视图中插入contentView将使单元格接触无效,ios,swift,Ios,Swift,我试图在UICollectionViewCell中的单元格内容后面添加滚动视图。然而,一旦我添加了它,我就选择了Cell。。。不再工作了。有什么想法吗 func build(){ scrollView = UIScrollView(frame: self.bounds) scrollView.scrollEnabled = true //Move the cell contents into the scrollview self.backgroundView
func build(){
scrollView = UIScrollView(frame: self.bounds)
scrollView.scrollEnabled = true
//Move the cell contents into the scrollview
self.backgroundView = scrollView
self.contentView.removeFromSuperview()
scrollView.addSubview(self.contentView)
var contentSize = self.bounds
contentSize.size.width += 100
self.scrollView.contentSize = contentSize.size
}
从
UICollectionViewCell
中删除contentView
不是一件好事。考虑添加<代码> ScLabVIEW < /代码>作为“代码>内容视图< /代码>的子视图。我正在进行扫描以显示单元格。所以我需要将单元格的所有内容添加到scrollview中。不,我认为视图层次结构是这样的。contentView->scrollView->containerView。您可以将所有内容放在containerView中,它会在scrollView中滚动。或者根本不使用scrollView。使用uipangestureerecognizer
更改contentView
的center.x
属性。但如果我想知道运行时单元格上有什么内容,该怎么办?它不是来自数据源对象吗?您可以从UICollectionView
中“indexPath”并查找数据