0

I've created animation ( CABasicAnimation(keyPath = "position.x") ) using 40 images. per image duration is 3 seconds. So, total duration of the core animation is 120 seconds inside a CALayer.
I'm using a UISlider to perform seek operation . For example when slider value is 5, I need to display image which came/ will come exactly in 5 second and continue core animation as well. How to perform forward and backward seek operation inside core animation?

Here is my code for animation

let animation = CABasicAnimation()
animation.keyPath = "position.x"
animation.fromValue = -viewSize.width
animation.toValue =  (viewSize.width)/2
animation.duration = 3
animation.speed = 1 // 1 is default actually
animation.beginTime = CACurrentMediaTime() + animationTimes[index-1] // here animationTimes is array like [0,3,6,9 ...... so on]
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
blackLayer.add(animation, forKey: "basic"). // here per blackLayer contain individual imageLayer and animation             
parentLayer.addSublayer(blackLayer)
sagarthecoder
  • 137
  • 1
  • 9
  • Can you @matt help me to understand timeOffSet? I read some article but can't understand properly what's the use of timeOffSet. I've updated my question . Please check again – sagarthecoder May 11 '21 at 07:10
  • And how to timeOffSet is used for backward seek operation? – sagarthecoder May 11 '21 at 07:24
  • I don’t understand where the images are. Your animation slides the black layer sideways. But I take it the goal is that the amount of sliding of the Slider is to be reflected by the amount of sliding of the layer. You don’t really need an animation for that but you can certainly do it that way. – matt May 11 '21 at 07:46
  • I have some downloadable examples such as https://github.com/mattneub/Programming-iOS-Book-Examples/blob/604368f458076dd40a8f4d0676a2aa79adb8e390/bk2ch04p160frozenAnimation/FrozenAnimationTest/ViewController.swift – matt May 11 '21 at 07:48
  • I added images before to blackLayer. I didn't write it here. By the way, can you give me a demo code for backward and forward seek operation? – sagarthecoder May 11 '21 at 07:49
  • But this is a lot closer to what you probably want. https://github.com/mattneub/Programming-iOS-Book-Examples/blob/604368f458076dd40a8f4d0676a2aa79adb8e390/bk2ch04p133FrozenAnimation/FrozenAnimation/ViewController.swift – matt May 11 '21 at 07:50

0 Answers0