Skip to content

Commit

Permalink
Add ‘scrollOffset’ property
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Feb 21, 2017
1 parent f72e492 commit 00474bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion FSPagerView/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
return self.collectionView.isTracking
}

open var scrollOffset: CGFloat {
let scrollOffset = Double(self.collectionView.contentOffset.x.divided(by: self.collectionViewLayout.itemSpan))
return fmod(CGFloat(scrollOffset), CGFloat(Double(self.numberOfItems)))
}

// MARK: - Public readonly-properties

open fileprivate(set) dynamic var currentIndex: Int = 0
Expand Down Expand Up @@ -312,7 +317,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if self.numberOfItems > 0 {
// In case someone is using KVO
let currentIndex = lround(Double(scrollView.contentOffset.x.divided(by: self.collectionViewLayout.itemSpan))) % self.numberOfItems
let currentIndex = lround(Double(self.scrollOffset))
if (currentIndex != self.currentIndex) {
self.currentIndex = currentIndex
}
Expand Down

0 comments on commit 00474bf

Please sign in to comment.