From 2ddf88b3225f3797b2f16b4e8d454b76aba96ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Fe=CC=81vrier?= Date: Mon, 28 Aug 2017 22:24:22 +0200 Subject: [PATCH] Add property to customize the animation duration --- Sources/FSPagerView.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/FSPagerView.swift b/Sources/FSPagerView.swift index bcc9b64..380cf9f 100644 --- a/Sources/FSPagerView.swift +++ b/Sources/FSPagerView.swift @@ -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 { @@ -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() {