【发布时间】:2019-10-09 00:52:28
【问题描述】:
我正在测试一些代码,看起来在 iOS13 中 UICollectionViewFlowLayout 没有收到 collectionView 框架中的更改。
下面是一个示例代码,其中我只是根据我在collectionView下方的tableview中滚动的量来改变collectionView的高度:
视图控制器
func scrollViewDidScroll(_ scrollView: UIScrollView) {
collectionView.collectionViewLayout.invalidateLayout()
let totalScroll = scrollView.contentSize.height - scrollView.bounds.size.height
let offset = (scrollView.contentOffset.y)
let percentage = offset / totalScroll
var frame = collectionView.frame
frame.size.height = 40 - (40 * percentage)
collectionView.frame = frame
}
CustomCollectionViewFlowLayout:UICollectionViewFlowLayout
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElements(in: rect)
print(collectionView?.frame)
return attributes
}
iOS 12 及以下版本的 CustomCollectionViewFlowLayout 中的打印语句正确打印出 collectionView.frame 中的更改,即高度实际更改。但在 iOS 13 中,它根本没有体现出来。
帮助任何人?
【问题讨论】:
-
不确定它是否相关,但我们发现
traitCollectionDidChange和viewWillTransition在 iOS 13 中不再在视图加载时被调用——我们必须将一些逻辑移动到viewDidLoad以进行初始设置。更多信息在这里developer.apple.com/documentation/ios_ipados_release_notes/…
标签: swift uicollectionview ios13 flowlayout