Created
September 30, 2017 01:50
-
-
Save mayoralito/2162a1b94bf6d311912c6f53a71911f9 to your computer and use it in GitHub Desktop.
radars
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
class ViewController: UIViewController { | |
var animator: UIDynamicAnimator! | |
var gravity: UIGravityBehavior! | |
var collision: UICollisionBehavior! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// -------------------------------------- | |
// | |
let customView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100)) | |
// more code.... | |
// | |
animator = UIDynamicAnimator(referenceView: view) | |
// mode code.... | |
// | |
collision = UICollisionBehavior(items: [customView]) | |
collision.collisionDelegate = self | |
// more code | |
animator.addBehavior(collision) | |
} | |
} | |
extension ViewController: UICollisionBehaviorDelegate { | |
// This will be marked as a warning suggesting to add private property because it nearly matches one of the UICollisionBehaviorDelegate methods. | |
// but it's the same deinition. | |
func collisionBehavior(_ behavior: UICollisionBehavior, beganContactFor item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying?, at p: CGPoint) { | |
print("Boundary contact occurred - \(String(describing: identifier))") | |
guard let collidingView = item as? UIView else { return } | |
collidingView.backgroundColor = UIColor.yellow | |
UIView.animate(withDuration: 0.3) { | |
collidingView.backgroundColor = UIColor.gray | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment