From 0bf4d2c7953d5c3d78ea868d2b41e4a7452b3e39 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 9 Sep 2020 17:37:37 +0900 Subject: [PATCH] call layoutIfNeeded before doing batch updates --- StackScrollView/StackScrollView.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/StackScrollView/StackScrollView.swift b/StackScrollView/StackScrollView.swift index 91610ba..e343089 100644 --- a/StackScrollView/StackScrollView.swift +++ b/StackScrollView/StackScrollView.swift @@ -115,6 +115,8 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl open func insert(views _views: [UIView], at index: Int, animated: Bool) { + layoutIfNeeded() + var _views = _views _views.removeAll(where: views.contains(_:)) views.insert(contentsOf: _views, at: index) @@ -164,7 +166,9 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl } open func remove(view: UIView, animated: Bool) { - + + layoutIfNeeded() + if let index = views.firstIndex(of: view) { views.remove(at: index) if animated { @@ -200,6 +204,8 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl open func remove(views: [UIView], animated: Bool) { + layoutIfNeeded() + var indicesForRemove: [Int] = [] for view in views {