When I try to get cell's intrinsicContentSize
in function collectionView(_:didSelectItemAt:)
, the result is (-1, -1).
I am using flow layout with auto layout config of cell's subviews and did not implement collectionView(_:layout:sizeForItemAt:)
. Does anyone have ideas?
Edit:
the auto layout of cell has fixed width and height. I turned on self-sizing by setting estimatedItemSize
and config the collectionView as following:
self.collectionView.delegate = self
self.collectionView.dataSource = self
if let layout = self.collectionView.collectionViewLayout as?
UICollectionViewFlowLayout {
layout.estimatedItemSize = CGSize(width: 100, height: 100)
}
And I try to get the cell's intrinsicContentSize
in:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
let size = cell?.intrinsicContentSize
}
which gives me (-1, -1)
for size