From 4a33bb5d4c01f16ff928bed4e1bf799070a9305a Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 9 Sep 2020 20:21:17 +0900 Subject: [PATCH] call layoutIfNeeded before doing batch updates (#13) --- 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 {