I've been learning swift for one week now and after creating my first app which uses Weather API I wanted to create simple animation: there is an image in LaunchScreen.storyboard with background and I wanted to animate the image to shrink to 0 so that my other ViewController would appear as normal. I've made something like this but there is problem, after the animation is finished Main ViewController appears and there is no animation inside of it. Moreover I wanted this image to increase its size slightly and then shrink - maybe there is another way to do it in one UIView.animate?
afterLaunchVC.swift:
class afterLaunchVC: UIViewController {
@IBOutlet weak var logoImg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
//increasing the size
UIView.animate(withDuration: 0.1, animations: ({
self.logoImg.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
}), completion: nil)
//shrinking the image after increasing
UIView.animate(withDuration: 1.0, animations: ({
self.logoImg.transform = CGAffineTransform(scaleX: 0.00001, y: 0.00001)
}), completion:{ //performingSegue
finished in self.performSegue(withIdentifier: "MainVC", sender: self)
})
}
}
As you can see as a UIView.animate completion I've set performSegue and turned off the animation of it but can't get animation in MainVC.swift (IBOutlets appear normally but without animation)
MainVC.swift:
class MainVC: UIViewController {
@IBOutlet weak var topLabel: UILabel!
@IBOutlet weak var hourLabel: UILabel!
@IBOutlet weak var remainingTimeLabel: UILabel!
var time : TimeTrack!
override func viewDidLoad() {
super.viewDidLoad()
topLabel.center.y = self.view.frame.height + 100
hourLabel.center.y = self.view.frame.height + 100
remainingTimeLabel.center.y = self.view.frame.height + 100
UIView.animate(withDuration: 2.6, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 3.0, options: [], animations: ({
self.topLabel.center.y = self.view.frame.height/2
}), completion: nil)
UIView.animate(withDuration: 2.5, delay: 0.1, usingSpringWithDamping: 1.0, initialSpringVelocity: 3.0, options: [], animations: ({
self.hourLabel.center.y = self.view.frame.height/2
}), completion: nil)
UIView.animate(withDuration: 2.4, delay: 0.2, usingSpringWithDamping: 1.0, initialSpringVelocity: 3.0, options: [], animations: ({
self.remainingTimeLabel.center.y = self.view.frame.height/2 - 30
}), completion: nil)
// further code...
}
I hope someone will explain what's wrong here because I'm new to this language