Я пытаюсь создать ячейки с автоматической высотой на CollectionView.
У меня есть 2 разные ячейки, которые работают.
Когда я поворачиваю устройство landscape
, я изменяю наавтоматическая высота и ширина.Оно работает.Но при возврате к portrait
это не так:
func checkEstimatedSize(){
if(DeviceType.IS_IPAD || UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight){
if let layout = myCollectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.estimatedItemSize = CGSize(width: 1, height: 1)
layout.invalidateLayout()
}
}else{
if(UIDevice.current.orientation == .portrait || UIDevice.current.orientation == .portraitUpsideDown){
if let layout = myCollectionView.collectionViewLayout as? UICollectionViewFlowLayout {
//get width of CollectionView
layout.estimatedItemSize = CGSize(width: 0, height: 1)
layout.invalidateLayout()
}
}
}
}
При портретной ориентации я хочу, чтобы ширина была такой же, как CollectionView, но высота зависит от содержимого ячейки.
Я знаю, что есть sizeForItemAt indexPath
, но как проверить / установить "autoheight" для ячейки (или CollectionView).
Извините, я не эксперт, поэтому яспрашиваю экспертов ...
Заранее спасибо.
РЕДАКТИРОВАТЬ:
оказывается, что я изменил layout.estimatedItemSize = CGSize(width: myCollectionView.frame.width, height: 0)
на второй еще и вроде работает ... но сейчасЯ получаю предупреждение плюс замораживание симулятора: The behavior of the UICollectionViewFlowLayout is not defined because:
MyApp the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
идей?