From 08daae1d4ce1bfbbd001d873c64398b71edbd932 Mon Sep 17 00:00:00 2001 From: WenchaoD Date: Thu, 11 Oct 2018 14:01:46 +0800 Subject: [PATCH] Prevent 'currentIndex' of FSPagerView to be changed during a 'possible' rotating. --- Sources/FSPagerView.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/FSPagerView.swift b/Sources/FSPagerView.swift index 1492e23..7ee1e49 100644 --- a/Sources/FSPagerView.swift +++ b/Sources/FSPagerView.swift @@ -221,7 +221,6 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega internal weak var collectionViewLayout: FSPagerViewLayout! internal weak var collectionView: FSPagerCollectionView! internal weak var contentView: UIView! - internal var timer: Timer? internal var numberOfItems: Int = 0 internal var numberOfSections: Int = 0 @@ -253,10 +252,15 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega } return IndexPath(item: 0, section: 0) } - + fileprivate var isPossiblyRotating: Bool { + guard let animationKeys = self.contentView.layer.animationKeys() else { + return false + } + let rotationAnimationKeys = ["position", "bounds.origin", "bounds.size"] + return animationKeys.contains(where: { rotationAnimationKeys.contains($0) }) + } fileprivate var possibleTargetingIndexPath: IndexPath? - // MARK: - Overriden functions public override init(frame: CGRect) { @@ -387,7 +391,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega } public func scrollViewDidScroll(_ scrollView: UIScrollView) { - if self.numberOfItems > 0 { + if !self.isPossiblyRotating && self.numberOfItems > 0 { // In case someone is using KVO let currentIndex = lround(Double(self.scrollOffset)) % self.numberOfItems if (currentIndex != self.currentIndex) {