获取CollectionViewContentSize

时间:2015-11-19 09:57:34

标签: ios objective-c swift

我试图在Apple的Photo Objective C实现中完成CollectionViewContentSize。以下是代码

Apple的代码

 CGSize cellSize = ((UICollectionViewFlowLayout *)self.collectionViewLayout).itemSize;

我的代码

 let cellSize: CGSize = UICollectionViewFlowLayout.collectionViewContentSize(self.collectionViewLayout)

我收到错误(UICollectionViewLayout) -> 'is not convertible to 'UICollectionViewFlowLayout -> () -> CGSize'

2 个答案:

答案 0 :(得分:2)

很简单: self.collectionViewLayout返回UICollectionViewLayout类型而不是UICollectionViewFlowLayout,所以你应该把它投出来:

if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
    let cellSize: CGSize = UICollectionViewFlowLayout.collectionViewContentSize(layout)()
}

答案 1 :(得分:0)

ObjC

  CGSize cellSize = ((UICollectionViewFlowLayout *)self.collectionViewLayout).itemSize;

夫特

  let cellSize: CGSize = self.collectionViewLayout.itemSize