Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding UICollisionBehavior
lazy var collider:UICollisionBehavior = {
let lazyCollider = UICollisionBehavior()
// This line, makes the boundries of our reference view a boundary
// for the added items to collide with.
lazyCollider.translatesReferenceBoundsIntoBoundary = true
return lazyCollider
}()
// This is how our animate function will look like
func animateSquare(){
animator.addBehavior(gravity)
// Add the collider also to the animator
animator.addBehavior(collider)
// Add the squareView to both behaviors
collider.addItem(squareView)
gravity.addItem(squareView)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment