所以我见过其他SO问题,但我无法弄明白我的
我知道我的UIScrollView代码有效,因为我在常规的UIViewController中测试它,所以我不认为contentSize是问题,但是当我将相同的代码放在UICollectionReusableView中时它不再滚动
-Working in UIViewController
override func viewDidLoad() {
super.viewDidLoad()
let scrollingView = colorButtonsView(buttonSize: CGSize(width:100.0,height:50.0), buttonCount: 10)
let scrollView = UIScrollView(frame: UIScreen.main.bounds)
scrollView.backgroundColor = UIColor.black
scrollView.contentSize = scrollingView.frame.size
scrollView.showsHorizontalScrollIndicator = true
self.view.addSubview(scrollView)
scrollView.addSubview(scrollingView)
}
-Not working in UICollectionReusableView
override init(frame: CGRect) {
super.init(frame: frame)
//Add category scroll view
let scrollingView = colorButtonsView(buttonSize: CGSize(width:100.0,height:50.0), buttonCount: 10)
let scrollView = UIScrollView(frame: UIScreen.main.bounds)
scrollView.backgroundColor = UIColor.black
scrollView.contentSize = scrollingView.frame.size
scrollView.showsHorizontalScrollIndicator = true
self.addSubview(scrollView) //Only changes self.view to self
scrollView.addSubview(scrollingView)
}
答案 0 :(得分:1)
迟到总比没有...我遇到了同样的问题,所以也许这就是原因;
我想在UIScrollView
内加UICollectionReusableView
,但不小心我创建了自定义类;
class CustomCellHeader: UICollectionViewCell {
}
而不是;
class CustomCellHeader: UICollectionReusableView {
}
一旦我改变了这一点,我的标题单元格中的UIScrollView
变为现实!