Prevent 'currentIndex' of FSPagerView to be changed during a 'possible' rotating.

This commit is contained in:
WenchaoD 2018-10-11 14:01:46 +08:00
parent 3711f2998d
commit 08daae1d4c
1 changed files with 8 additions and 4 deletions

View File

@ -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) {