swift 中的 CollectionViewFlowLayout 的 collectionViewContentSize()
CollectionViewFlowLayout's collectionViewContentSize() in swift
我无法使用以下代码从流布局中检索 contentSize
let contentSize: CGSize = self.collectionView?.collectionViewLayout.collectionViewContentSize()!
相反,我得到错误:
Could not find member 'collectionViewContentSize'
如果我正确打印它的值 returns:
println("content size \(self.collectionView?.collectionViewLayout.collectionViewContentSize())")
这是 swift 编译器问题吗?
您必须将collectionViewLayout
转换为特定布局。如果你使用 UICollectionViewFlowLayout
它将看起来像这样:
if let flow = collectionMain.collectionViewLayout as? UICollectionViewFlowLayout
{
let contentSize: CGSize = flow.collectionViewContentSize()
}
我无法使用以下代码从流布局中检索 contentSize
let contentSize: CGSize = self.collectionView?.collectionViewLayout.collectionViewContentSize()!
相反,我得到错误:
Could not find member 'collectionViewContentSize'
如果我正确打印它的值 returns:
println("content size \(self.collectionView?.collectionViewLayout.collectionViewContentSize())")
这是 swift 编译器问题吗?
您必须将collectionViewLayout
转换为特定布局。如果你使用 UICollectionViewFlowLayout
它将看起来像这样:
if let flow = collectionMain.collectionViewLayout as? UICollectionViewFlowLayout
{
let contentSize: CGSize = flow.collectionViewContentSize()
}