Last active
May 6, 2016 12:40
-
-
Save 15458434/bfa848e28054131efdf7da1f5ede590e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import UIKit | |
import XCPlayground | |
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 667)) | |
containerView.backgroundColor = UIColor.whiteColor() | |
XCPlaygroundPage.currentPage.liveView = containerView | |
let square = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100)) | |
square.backgroundColor = UIColor.grayColor() | |
containerView.addSubview(square) | |
let animator = UIDynamicAnimator(referenceView: containerView) | |
let gravity = UIGravityBehavior(items: [square]) | |
animator.addBehavior(gravity) | |
let barrier = UIView(frame: CGRect(x: 0, y: 300, width: 130, height: 20)) | |
barrier.backgroundColor = UIColor.redColor() | |
containerView.addSubview(barrier) | |
let collision = UICollisionBehavior(items: [square]) | |
collision.translatesReferenceBoundsIntoBoundary = true | |
animator.addBehavior(collision) | |
let rightEdge = CGPoint(x: barrier.frame.origin.x + barrier.frame.size.width, y: barrier.frame.origin.y) | |
collision.addBoundaryWithIdentifier("barrier", fromPoint: barrier.frame.origin, toPoint: rightEdge) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment