重力は何もしていないようです。それを機能させる方法がわかりません。これが私のコードです。赤いボックスは移動せずにそのままです。
class ViewController: UIViewController {
var box : UIView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
addBox(CGRectMake(100, 100, 30, 30))
createAnimation()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func addBox(location: CGRect) {
let newBox = UIView(frame: location)
newBox.backgroundColor = UIColor.redColor()
view.insertSubview(newBox, atIndex: 0)
box = newBox
}
func createAnimation(){
var animate = UIDynamicAnimator(referenceView: self.view)
println("animation")
var gravity = UIGravityBehavior(items: [box])
gravity.gravityDirection = CGVectorMake(0, 0.6)
animate.addBehavior(gravity)
}
}