SegmentedProgressBar icon indicating copy to clipboard operation
SegmentedProgressBar copied to clipboard

Rewind one story

Open michael-martinez opened this issue 7 years ago • 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.

michael-martinez avatar Sep 13 '18 10:09 michael-martinez

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

}

michael-martinez avatar Sep 13 '18 11:09 michael-martinez

Hello @michael-martinez are you using this with collection view ?

dineshguptha avatar Dec 03 '18 06:12 dineshguptha

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.

kiet1993 avatar Dec 13 '18 03:12 kiet1993