以下のメソッドがcollectionViewのスクロール後に呼ばれないです。
原因がわからない状態です。
// MARK: - UIScrollViewDelegate extension TabView: UICollectionViewDelegate { func scrollViewDidScroll(scrollView: UIScrollView) { if scrollView.dragging { currentBarView.hidden = true let indexPath = NSIndexPath(forItem: currentIndex, inSection: 0) if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? TabCollectionCell { cell.showCurrentBarView() } } guard isInfinity else { return } if pageTabItemsWidth == 0.0 { pageTabItemsWidth = floor(scrollView.contentSize.width / 3.0) } if (scrollView.contentOffset.x <= 0.0) || (scrollView.contentOffset.x > pageTabItemsWidth * 2.0) { scrollView.contentOffset.x = pageTabItemsWidth } } func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) { // Accept the touch event because animation is complete updateCollectionViewUserInteractionEnabled(true) guard isInfinity else { return } let indexPath = NSIndexPath(forItem: currentIndex, inSection: 0) if shouldScrollToItem { // After the moved so as not to sense of incongruity, to adjust the contentOffset at the currentIndex collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: false) shouldScrollToItem = false } } }
func moveCurrentBarView(indexPath: NSIndexPath, animated: Bool, shouldScroll: Bool) { if shouldScroll { collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: animated) layoutIfNeeded() collectionViewContentOffsetX = 0.0 currentBarViewWidth = 0.0 } if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? TabCollectionCell { currentBarView.hidden = false if animated && shouldScroll { cell.isCurrent = true } cell.hideCurrentBarView() currentBarViewWidthConstraint.constant = cell.frame.width if !isInfinity { currentBarViewLeftConstraint?.constant = cell.frame.origin.x } UIView.animateWithDuration(0.2, animations: { self.layoutIfNeeded() }, completion: { _ in if !animated && shouldScroll { cell.isCurrent = true } if !self.isInfinity { self.updateCollectionViewUserInteractionEnabled(true) } }) } beforeIndex = currentIndex }
TabViewは以下のように設定しています!
回答よろしくおねがいします!!
moveCurrentBarView()内の if shouldScroll { の次の行に print(indexPath, animated, shouldScroll) を追加して、出力を教えて下さい。