Hello everybody,
I have an animation to create ballons floating from the bottom to the top of the screen. Despite producing the behaviour I want, at some point, when the ballons are floating upwards the objectView I am using one ballon gets printed at the top left corner of the screen and does not move or disappear.
Has this ever happend to any of you?
func presentVictoryView(word: String) {
blackView.isHidden = false
for _ in 0 ... 30 {
let objectView = UIView()
objectView.translatesAutoresizingMaskIntoConstraints = false
objectView.frame = CGRect(x: 0, y: 0, width: 20, height: 100)
objectView.backgroundColor = .clear
//objectView.alpha = CGFloat(0.9)
objectView.isHidden = false
let ballon = UILabel()
ballon.translatesAutoresizingMaskIntoConstraints = false
ballon.frame = CGRect(x: 0, y: 0, width: 20, height: 100)
ballon.backgroundColor = .clear
//ballon.alpha = CGFloat(0.9)
ballon.text = ""
ballon.font = UIFont.systemFont(ofSize: 60)
objectView.addSubview(ballon)
NSLayoutConstraint.activate([
ballon.centerXAnchor.constraint(equalTo: objectView.centerXAnchor),
ballon.centerYAnchor.constraint(equalTo: objectView.centerYAnchor)
])
blackView.addSubview(objectView)
let randomXOffset = Int.random(in: -120 ..< 200)
let path = UIBezierPath()
path.move(to: CGPoint(x: 160 + randomXOffset, y: 1000))
path.addCurve(to: CGPoint(x: 100 + randomXOffset, y: -300), controlPoint1: CGPoint(x: 300 - randomXOffset, y: 600), controlPoint2: CGPoint(x: 70 + randomXOffset, y: 300))
let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = path.cgPath
animation.repeatCount = 1
animation.duration = Double(arc4random_uniform(40) + 30) / 10
//animation.timeOffset = Double(arc4random_uniform(50))
objectView.layer.add(animation, forKey: "animate position along path")
}
newGame()
}
I have tried a lot of things... I don't know what I am doing wrong...
Thank you!