Wenn ich versuche, Zelle intrinsicContentSize
in Funktion collectionView(_:didSelectItemAt:)
zu erhalten, ist das Ergebnis (-1, -1).Swift3 - UICollectionViewCel's intrinsicContentSize ist (-1, -1)
Ich verwende Flow-Layout mit Auto-Layout-Konfiguration der Zelle Subviews und implementiert nicht collectionView(_:layout:sizeForItemAt:)
. Hat jemand Ideen?
Edit:
die automatische Layout-Zelle hat die Breite und Höhe festgelegt. Ich drehte mich auf Selbst Dimensionierung von estimatedItemSize
Einstellung und die Collection Config wie folgt:
self.collectionView.delegate = self
self.collectionView.dataSource = self
if let layout = self.collectionView.collectionViewLayout as?
UICollectionViewFlowLayout {
layout.estimatedItemSize = CGSize(width: 100, height: 100)
}
Und ich versuche die Zelle intrinsicContentSize
in zu erhalten:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
let size = cell?.intrinsicContentSize
}
die mich (-1, -1)
für size
mehr Code setzen Sie implementiert haben Antwort –
Check out http://stackoverflow.com/questions/24127032/proper-usage-of-intrinsiccontentsize-and-sizethatfits-on-uiview-subclass-with-a –