I've used invalidateIntrinsicContentSize()
in UICollectionViewCell to calculate custom UI. But it doesn't invoke intrinsicContentSize
on iOS beta 16 devices..
class DynamicCell: UICollectionViewCell {
func invokeResize() {
cell.subviews.forEach { $0.resize() }
// it doesn't invoke intrinsicContentSize from iOS 16 beta ??
invalidateIntrinsicContentSize()
}
override func intrinsicContentSize: CGSize {
return calculateDynamicCellSize()
}
}
I don't know if it is a bug or a specification that occurred while implementing UICollectionView.selfSizingInvalidation
property.
I could revise this code for iOS beta 16 using parent's( UICollectionReusableView
| UIView
) methods like below.
class RevisedDynamicCell: UICollectionViewCell {
func invokeResize() {
cell.subviews.forEach { $0.resize() }
if #available(iOS 16.0, *) {
// It works because it called UIView.invalidateIntrinsicContentSize
invalidateUIViewIntrinsicContentSize()
} else {
invalidateIntrinsicContentSize()
}
}
override func intrinsicContentSize: CGSize {
return calculateDynamicCellSize()
}
}
extension UICollectionReusableView {
func invalidateUIViewIntrinsicContentSize() {
super.invalidateIntrinsicContentSize()
}
}```