Skip to content

Instantly share code, notes, and snippets.

@ahmed-abdurrahman
Created October 21, 2015 06:57
Show Gist options
  • Save ahmed-abdurrahman/05b0526a7d700044b295 to your computer and use it in GitHub Desktop.
Save ahmed-abdurrahman/05b0526a7d700044b295 to your computer and use it in GitHub Desktop.
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