import UIKit
class ViewController : UIViewController {
@IBOutlet weak var imageView: UIImageView !
var dynamicAnimator = UIDynamicAnimator ()
override func viewDidLoad() {
super .viewDidLoad()
dynamicAnimator = UIDynamicAnimator (referenceView: self .view)
//创建并添加重力行为
let gravityBehavior = UIGravityBehavior (items: [ self .imageView])
dynamicAnimator.addBehavior(gravityBehavior)
//创建并添加碰撞行为
let collisionBehavior = UICollisionBehavior (items: [ self .imageView])
collisionBehavior.translatesReferenceBoundsIntoBoundary = true
dynamicAnimator.addBehavior(collisionBehavior)
}
override func didReceiveMemoryWarning() {
super .didReceiveMemoryWarning()
}
}
|