Skip to content

Commit 29f9a30

Browse files
author
Richard Février
committed
Add property to customize the animation duration
1 parent 72edd3f commit 29f9a30

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sources/FSPagerView.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
101101
}
102102
}
103103

104+
@IBInspectable
105+
open var automaticSlidingDuration: TimeInterval = 0.3 {
106+
didSet {
107+
self.cancelTimer()
108+
if self.automaticSlidingDuration > 0 {
109+
self.startTimer()
110+
}
111+
}
112+
}
113+
114+
104115
/// The time interval of automatic sliding. 0 means disabling automatic sliding. Default is 0.
105116
@IBInspectable
106117
open var automaticSlidingInterval: CGFloat = 0.0 {
@@ -536,7 +547,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
536547
let item = (indexPath.item+1) % self.numberOfItems
537548
return self.collectionViewLayout.contentOffset(for: IndexPath(item: item, section: section))
538549
}()
539-
self.collectionView.setContentOffset(contentOffset, animated: true)
550+
UIView.animate(withDuration: self.automaticSlidingDuration) {
551+
self.collectionView.contentOffset = contentOffset
552+
}
540553
}
541554

542555
fileprivate func cancelTimer() {

0 commit comments

Comments
 (0)