diff --git a/Sources/ButtonBarPagerTabStripViewController.swift b/Sources/ButtonBarPagerTabStripViewController.swift index 36e008d6..00bc282a 100644 --- a/Sources/ButtonBarPagerTabStripViewController.swift +++ b/Sources/ButtonBarPagerTabStripViewController.swift @@ -65,6 +65,8 @@ public struct ButtonBarPagerTabStripSettings { } open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource { + + private var shouldUpdateContent = true public var settings = ButtonBarPagerTabStripSettings() @@ -192,12 +194,23 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa // MARK: - Public Methods open override func reloadPagerTabStripView() { + shouldUpdateContent = false super.reloadPagerTabStripView() + shouldUpdateContent = true + guard isViewLoaded else { return } buttonBarView.reloadData() cachedCellWidths = calculateWidths() + buttonBarView.layoutIfNeeded() + updateContent() buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes) } + + open override func updateContent() { + if shouldUpdateContent { + super.updateContent() + } + } open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat { var numberOfLargeCells = 0 diff --git a/Sources/ButtonBarView.swift b/Sources/ButtonBarView.swift index a204971e..9b039d26 100644 --- a/Sources/ButtonBarView.swift +++ b/Sources/ButtonBarView.swift @@ -78,7 +78,10 @@ open class ButtonBarView: UICollectionView { open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat, pagerScroll: PagerScroll) { selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex - let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame + var fromFrame = CGRect.zero + if let layout = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0)) { + fromFrame = layout.frame + } let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0) var toFrame: CGRect