我正在将我的应用程序从OBJ-C转换为Swift。
我有一个覆盖" preparforlayout"的UicollectionViewLayout的子类,该子类已更名为"准备"。到目前为止,一切都很好。但是,在我的OBJ-C代码中,我有这一行:
self.contentSize = CGSizeMake(contentWidth, contentHeight+40);
'self'指的是自定义uicollectionViewLayout。
现在,在Swift中,当我尝试做
时self.contentSize = CGSize(width: contentWidth, height: contentHeight+40)
我得到此错误要求
" mycustomcollectionlayout"类型的值没有成员'contentsize'
我确实知道有类似 collectionViewContentsize 的东西,但这似乎在这里不合适。
我希望你们中的任何人都可以建议我如何进行
contentsize 不是 uicollectionViewLayout 属性,它是 uicollectionView 或 uiscrollview em>。
collectionView?.contentSize = CGSize(width: contentWidth, height: contentHeight+40)
,但是,为什么在CollectionView布局中需要这个。您应该真正考虑覆盖属性CollectionViewContentsize,这正是contentsize对UISCrollView的作用,
override var collectionViewContentSize: CGSize {
return CGSize(width: contentWidth, height: contentHeight+40)
}