Skip to content

Instantly share code, notes, and snippets.

@agibson73
Created October 16, 2016 19:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
let vw = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
vw.backgroundColor = UIColor.red
self.view.addSubview(vw)
vw.center = self.view.center
// Your code with delay
let spring = CASpringAnimation(keyPath: "position.y")
spring.toValue = vw.center.y - 200
spring.damping = 10.0
spring.initialVelocity = 8.0
spring.duration = spring.settlingDuration
spring.beginTime = CACurrentMediaTime() + 5.0
CATransaction.begin()
CATransaction.setCompletionBlock {
vw.layer.position.y = vw.center.y - 200
}
vw.layer.add(spring, forKey: nil)
CATransaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment