Skip to content

Instantly share code, notes, and snippets.

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