我将我的应用从Obj-C转换为Swift。
我有UICollectionViewLayout的这个子类,它会覆盖' prepareForLayout'已更名为'准备'。 到现在为止还挺好。 但是,在我的obj-c代码中,我有这一行:
self.contentSize = CGSizeMake(contentWidth, contentHeight+40);
其中' self'指自定义UICollectionViewLayout。
现在,在Swift中,当我尝试
时self.contentSize = CGSize(width: contentWidth, height: contentHeight+40)
我收到此错误声明
类型' myCustomCollectionLayout'的值没有会员' contentSize'
我知道有类似 collectionViewContentSize 的内容,但这似乎不合适。
我希望你们中的任何人都可以告诉我如何继续
答案 0 :(得分:0)
contentSize 不是 UICollectionViewLayout 属性,它是 UICollectionView 或 UIScrollView 的属性。
collectionView?.contentSize = CGSize(width: contentWidth, height: contentHeight+40)
但是,为什么在collectionview布局中需要这个。您应该考虑覆盖属性collectionViewContentSize,这正是contentSize为UIScrollView所做的,
override var collectionViewContentSize: CGSize {
return CGSize(width: contentWidth, height: contentHeight+40)
}