Skip to content

Instantly share code, notes, and snippets.

@agibson73
Created October 16, 2016 19:36
Show Gist options
  • Save agibson73/7866c631771c9036896ca3957a6bb550 to your computer and use it in GitHub Desktop.
Save agibson73/7866c631771c9036896ca3957a6bb550 to your computer and use it in GitHub Desktop.
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