我正在把我的应用程序从Obj转换成Swift。
我有一个UICollectionViewLayout的子类,它覆盖“prepareForLayout”,该子类已被重命名为“准备”。到目前一切尚好。然而,在我的obj-c代码中,我有以下一行:
self.contentSize = CGSizeMake(contentWidth, contentHeight+40);其中'self‘指的是自定义UICollectionViewLayout。
现在,在斯威夫特,当我试图做
self.contentSize = CGSize(width: contentWidth, height: contentHeight+40)我知道这个错误声称
类型'myCustomCollectionLayout‘的值没有成员'contentSize’
我确实知道有类似于collectionViewContentSize的东西,但这在这里似乎不合适。
我希望你们中的任何一个人能建议我如何继续
发布于 2018-03-24 08:35:26
contentSize不是UICollectionViewLayout属性,而是UICollectionView或UIScrollView上的属性。
collectionView?.contentSize = CGSize(width: contentWidth, height: contentHeight+40)但是,为什么你会要求这个,在集合视图布局。您应该考虑重写属性collectionViewContentSize,这正是contentSize为UIScrollView所做的,
override var collectionViewContentSize: CGSize {
return CGSize(width: contentWidth, height: contentHeight+40)
}https://stackoverflow.com/questions/49462730
复制相似问题