Bharath
Bharath

Reputation: 2114

In iOS "Spring" library for animation, Do we need to set "animation" property each time before calling "animate()" method?

I am using Spring library for animation effects in my app.

In my case I have to animate a button on action, So I have added the following code blocks.

override func viewDidLoad() {
    super.viewDidLoad()
    setOptions()
}
func setOptions() {
    testButton.animation = Spring.AnimationPreset.Shake.rawValue
    testButton.curve = Spring.AnimationCurve.EaseIn.rawValue
}
@IBAction func testButtonPressed(_ sender: Any) {
    animateView()
}

In this above code flow the animation action occurs only one time.

But if I update the "testButtonPressed" method as follows,

@IBAction func testButtonPressed(_ sender: Any) {
    setOptions()
    animateView()
}

The animation occurs each time I press the testButton.

Why do I have to update the animation property each time ? Isn't it enough to update properties only once ?

Upvotes: 0

Views: 172

Answers (1)

agibson007
agibson007

Reputation: 4373

In the library it appears that resetAll removes the animation type and all the attributes following the execution of the animation. This method is called in the completion of the animation block in the Spring file.

Here is a link to the Spring file in question as well as a copy of the function that removes the animation.

func resetAll() {
    x = 0
    y = 0
    animation = ""
    opacity = 1
    scaleX = 1
    scaleY = 1
    rotate = 0
    damping = 0.7
    velocity = 0.7
    repeatCount = 1
    delay = 0
    duration = 0.7
}

Hope this helps you understand why the animation is removed until you reset the animation type.

Upvotes: 0

Related Questions