2
私はセルとヘッダーを持つtableViewを持っています。ヘッダーは、スタックビュー内の2つのビューで構成されます。私はテーブルビューの幅が変更されるたびにヘッダの特定の高さを設定します。viewWillLayoutSubviewsで無限ループに陥ることはありませんか?
質問:どのように無限ループに陥ることはありませんか?ここでのコードは次のとおりです。
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
guard let flowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout else {
return
}
UIView.animate(withDuration: 0.5, animations: { [weak self] (_) in
self?.tableView.beginUpdates()
if (self?.filtersView.isHidden)! {
self?.filtersViewHeight.constant = .leastNormalMagnitude
self?.stackView.bounds.size.height = 45
} else {
self?.filtersViewHeight.constant = 100
self?.stackView.bounds.size.height = 45 + (self?.filtersViewHeight.constant)!
}
}, completion: { [weak self] (_) in
flowLayout.invalidateLayout()
self?.tableView.endUpdates() <---- this is wrong, as it forces the infinite loop.
})
}
はい、私はあなたのポイントを見て、これはまったく正しいです!ありがとう!数分で正解に設定されます – 6axter82