UICollectionView
在 iOS12 的BUG,自動布局無效煮甥。
- 解決辦法盗温,在
reloadData
之后調(diào)用,比較復雜成肘,刷新有時候有問題卖局。
// view did load layout
DispatchQueue.main.async {
collectionView.collectionViewLayout.invalidateLayout()
}
- 直接在
viewWillLayoutSubviews
中使用
// view will layout subviews
collectionView.collectionViewLayout.invalidateLayout()
- 使用
UICollectionView
子類實現(xiàn)。最好最保險双霍。
class CCAutoLayoutCollectionView: UICollectionView {
// once
private var shouldInvalidateLayout = false
override func layoutSubviews() {
super.layoutSubviews()
if shouldInvalidateLayout {
collectionViewLayout.invalidateLayout()
shouldInvalidateLayout = false
}
}
override func reloadData() {
shouldInvalidateLayout = true
super.reloadData()
}
}
navigationItem.titleView
在iOS13之前顯示問題
- 重寫內(nèi)容布局
layoutFittingExpandedSize
class YGBarTitleView: UIView {
override var intrinsicContentSize: CGSize {
UIView.layoutFittingExpandedSize
}
}