Rewind one story
michael-martinez opened this issue · 3 comments
I am trying to load a previous story but cannot manage to do so.
Here is the function I am trying to implement which should be the opposite action to skip() :
func rewindOne() {
let currentSegment = segments[currentAnimationIndex]
currentSegment.topSegmentView.frame.size.width = 0
currentSegment.topSegmentView.layer.removeAllAnimations()
var newIndex = self.currentAnimationIndex - 1
if newIndex < 0 { newIndex = 0 }
if newIndex >= 0 {
self.delegate?.segmentedProgressBarChangedIndex(index: newIndex)
self.animate(animationIndex: newIndex)
}
}
The animation does not stop, I have 3 items, tried:
segments.forEach {
$0.topSegmentView.layer.removeAllAnimations()
}
The segment keeps being animated.
Found one really inefficient but working solution :
spb.removeAllAnimations()
spb.removeFromSuperview()
spb = nil
spb = SegmentedProgressBar(numberOfSegments: self.playerItems.count, durations: self.playerItemsDuration)
spb.frame = CGRect(x: 15, y: 15, width: view.frame.width - 30, height: 4)
view.addSubview(spb)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.001) {
self.spb.startAnimation()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.001) {
for _ in 0..<self.currentStory {
self.spb.skip()
}
}
Hello @michael-martinez are you using this with collection view ?
I found a solution.
Add following code in SegmentedProgressBar class
You can call segmentedProgressBarChangedIndex delegate if you want to notify.
func rewindCurrentSegment(){
let currentSegment = segments[currentAnimationIndex]
currentSegment.topSegmentView.layer.removeAllAnimations()
currentSegment.topSegmentView.frame.size.width = 0
self.animate(animationIndex: currentAnimationIndex)
}
This is a simple project but very helpful. Easy to custome. Thanks dev team.