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