Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
More fun, by adding UIDynamicItemBehavior
lazy var dynamicItemBehavior:UIDynamicItemBehavior = {
let lazyBehavior = UIDynamicItemBehavior()
// Let's make our square elastic
// 0 = no elacticity, 1.0 = max elacticity
lazyBehavior.elasticity = 0.8
// Other configurations
// lazyBehavior.allowsRotation
// lazyBehavior.density
// lazyBehavior.friction
// lazyBehavior.resistance
return lazyBehavior
}()
func animateSquare(){
animator.addBehavior(gravity)
animator.addBehavior(collider)
// Add the dynamicItemBehavior to the animator
animator.addBehavior(dynamicItemBehavior)
collider.addItem(squareView)
gravity.addItem(squareView)
// And add the squareView to the dynamicItemBehavior
dynamicItemBehavior.addItem(squareView)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment