As the user taps on superview I am detecting it via UITapGestureRecognizer
and calling below function to create a UIImage
view, add it to superview, add gravity to it and let it fall out of the superview.
Problem is that if the user taps again while the first UIImage
is still on the screen, first image halts in place and the second UIImage
starts falling. What is the best way to let multiple UIImage
fall independently on the screen.
Secondly, I feel, I should be removing these UIImage
from superview to conserve memory (as there could be hundreds of taps but I cant figure out how to automatically remove a UIImage
as soon as it is out of the screen.
Help in swift please.
func dropBall(tapLocation:CGPoint) {
let ball = UIImageView(image: UIImage(named: "White50.png"))
ball.frame = CGRect(origin: CGPoint(x:tapLocation.x-25,y:tapLocation.y-25), size: CGSize(width:50,height:50))
view.addSubview(ball)
animator = UIDynamicAnimator(referenceView: self.view)
gravity = UIGravityBehavior(items: [ball])
animator.addBehavior(gravity)
}