Skip to content

Commit

Permalink
Add property to customize the animation duration
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardFevrier authored and Richard Février committed Aug 28, 2017
1 parent 72edd3f commit 2ddf88b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
}
}

@IBInspectable
open var automaticSlidingDuration: TimeInterval = 0.3 {
didSet {
self.cancelTimer()
if self.automaticSlidingDuration > 0 {
self.startTimer()
}
}
}


/// The time interval of automatic sliding. 0 means disabling automatic sliding. Default is 0.
@IBInspectable
open var automaticSlidingInterval: CGFloat = 0.0 {
Expand Down Expand Up @@ -536,7 +547,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
let item = (indexPath.item+1) % self.numberOfItems
return self.collectionViewLayout.contentOffset(for: IndexPath(item: item, section: section))
}()
self.collectionView.setContentOffset(contentOffset, animated: true)
UIView.animate(withDuration: self.automaticSlidingDuration) {
self.collectionView.contentOffset = contentOffset
}
}

fileprivate func cancelTimer() {
Expand Down

0 comments on commit 2ddf88b

Please sign in to comment.