Hi.
after i signed following function
i donโt seed any think in the log
func collisionBehavior(behavior: UICollisionBehavior!, beganContactForItem item: UIDynamicItem!, withBoundaryIdentifier identifier: NSCopying!, atPoint p: CGPoint) {
println(โBoundary contact occurred - (identifier)โ)
}
this is example from the project:==>>
import UIKit
protocol UIDynamicItem: NSObjectProtocol{
var center: CGPoint{get set}
var bounds: CGRect{get}
var transform: CGAffineTransform{get set}
}
class ViewController: UIViewController, UICollisionBehaviorDelegate {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
var collision: UICollisionBehavior!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let square = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
square.backgroundColor = UIColor.grayColor()
view.addSubview(square)
let barier = UIView(frame: CGRect(x: 0, y: 300, width: 130, height: 20))
barier.backgroundColor = UIColor.redColor()
view.addSubview(barier)
animator = UIDynamicAnimator(referenceView: view)
gravity = UIGravityBehavior(items: [square])
animator.addBehavior(gravity)
collision = UICollisionBehavior(items: [square])
collision.collisionDelegate = self
//collision = UICollisionBehavior(items: [square, barier])
collision.addBoundaryWithIdentifier("barier", forPath: UIBezierPath(rect: barier.frame))
collision.translatesReferenceBoundsIntoBoundary = true
animator.addBehavior(collision)
// collision.action = {
// print(โ(NSStringFromCGAffineTransform(square.transform)) (NSStringFromCGPoint(square.center))โ)
// }
}
func collisionBehavior(behavior: UICollisionBehavior, beganContactForItem item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying?, atPoint p: CGPoint) {
print("Boundary connect acured - \(identifier)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
gdubz
August 28, 2017, 7:56pm
3
Just ran through this and there are minor syntax issues with Swift 3 in Xcode 8.3.3, so Iโve uploaded my version of the resulting code after following the tutorial:
UIKit Dynamics Tutorial, updated for Swift 3 (Xcode 8.3.3)
This tutorial is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]