Andrea Mario Lufino Andrea Mario Lufino -4 years ago 43
iOS Question

iOS - Facebook pop framework - Repeat forever "shake" animation

I'm using Facebook pop framework to perform some cool animations. I'm shaking a button in this way :

let rotation = POPSpringAnimation.init(propertyNamed: kPOPLayerRotation)
rotation.springBounciness = 30
rotation.springSpeed = 20
rotation.velocity = 30.0
rotation.repeatForever = true

button.layer.pop_addAnimation(rotation, forKey: "rotation")

Despite of the
set to
the animation doesn't repeat. I noticed that if we have the
property set, the animation repeats. Am I doing something wrong?

Answer Source

You can do it with POPBasicAnimation. If you're rotating forever, you may not need the spring animation.

Looking at your code, you don't have a rotation.toValue You need to tell the animation how far to rotate. Try this:

func configureBtnRotation(btn: UIButton) {
  let rotation = POPBasicAnimation(propertyNamed: kPOPLayerRotation)
  rotation.toValue = 90.0
  rotation.duration = 100.0 //this sets the speed of rotation
  rotation.repeatForever = true
  button.layer.pop_addAnimation(rotation, forKey: "rotation")

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download