0

I'm using UIKit dynamics to create a falling object and i was wondering if i could actually slow the gravity to make the ball fall slower on command. For example, the object will be falling, I press a button, then the ball falls slower. How would i go about doing this? Here is my code (P.S. I added the squareView above this but I didn't include it because it's irrelevant to the question)

var squareView: UIImageView!
var gravity: UIGravityBehavior!
var animator: UIDynamicAnimator!
var collision: UICollisionBehavior!
func viewDidLoad() {
    super.viewDidLoad()

    animator = UIDynamicAnimator(referenceView: view)
    gravity = UIGravityBehavior(items: [squareView])
    gravity.gravityDirection = CGVector(dx: 0.0, dy: 1.1)
    animator.addBehavior(gravity)
}

I tried writing gravity.gravityDirection = CGVector(dx: 0.0, dy: 0.5) but it just flung the object across the screen frantically so I don't know what to do here.

matt
  • 515,959
  • 87
  • 875
  • 1,141

1 Answers1

1

You can change the magnitude of gravity behavior. (Alternatively, possibly you can change the drag of the falling object by giving it a UIDynamicItemBehavior with resistance, but I haven't tried that so I'm not certain of it.)

matt
  • 515,959
  • 87
  • 875
  • 1,141