Reputation: 130
I have a view initially located at position A , and two other positions named B and C.
This image shows the initial state of the view.
What I want to achieve is to animate the view from B to C, but in a different way.
I want the animation object to start from A and finishes at C but skips the A→B part, performing only the B→C part.
The code should look like this :
// aLabel and cLabel are the labels shown in the image above
let a = aLabel.center.x
let c = cLabel.center.x
let animation = CABasicAnimation(keyPath: "position.x")
animation.duration = 3
// The animation should start in code from A
animation.fromValue = a
// And ends at C
animation.toValue = c
// Update the model layer
someView.layer.position.x = c
/* ADD SOMETHING TO MAKE THE ANIMATION
STARTS FROM B AND ENDS AT C */
I tried to set the animation offset to 1.5 :
animation.timeOffset = 1.5
But It didn't work. The animation executes as following: B → C → A → B , I only want B → C
Upvotes: 2
Views: 241
Reputation: 1273
To jump the A→B part, you can set the fromValue
to bLabel center.
animation.fromValue = bLabel.center.x
if you want to keep the fromValue
and toValue
set the repeatDuration
along with timeOffset
:
animation.timeOffset = 1.5
animation.repeatDuration = 1.5
Upvotes: 3