Created
July 16, 2020 10:02
-
-
Save stevencurtis/c4da406115ce20a402dad8bc20acd5f6 to your computer and use it in GitHub Desktop.
animate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animate(duration: TimeInterval, delay: TimeInterval) { | |
UIView.animate(withDuration: 0.5, delay: 0, options: [.curveEaseOut], animations: { | |
self.tree0.alpha = 1.0 | |
self.city.alpha = 1.0 | |
self.city2.alpha = 1.0 | |
self.manImage.alpha = 1.0 | |
}, completion: nil) | |
// tree must disappear off the screen, so -50 | |
let treeAnimation = CABasicAnimation(keyPath: "position.x") | |
treeAnimation.duration = duration | |
let treeMid: Double = Double(self.city.frame.size.width) | |
treeAnimation.fromValue = NSNumber(value: treeMid) | |
treeAnimation.toValue = NSNumber(value: -50 ) | |
treeAnimation.repeatCount = .infinity | |
self.tree0.layer.add(treeAnimation, forKey: "basic") | |
let firstCityAnimation = CABasicAnimation(keyPath: "position.x") | |
firstCityAnimation.duration = duration | |
firstCityAnimation.fromValue = NSNumber(value: 0.0) | |
firstCityAnimation.toValue = NSNumber(value: -1 * Int(self.city.frame.size.width)) | |
firstCityAnimation.repeatCount = .infinity | |
self.city.layer.add(firstCityAnimation, forKey: "basic") | |
let secondCityAnimation = CABasicAnimation(keyPath: "position.x") | |
secondCityAnimation.duration = duration | |
secondCityAnimation.fromValue = NSNumber(value: Int(self.city.frame.size.width) ) | |
secondCityAnimation.toValue = NSNumber(value: 0 ) | |
secondCityAnimation.repeatCount = .infinity | |
self.city2.layer.add(secondCityAnimation, forKey: "basic") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment