Reputation: 768
Hey so i want a button in my view to grow when the view loads with a little animation.
When the view loads ect i set the start values
override func viewWillAppear(_ animated: Bool) {
let shrink = CGAffineTransform(scaleX: 0, y: 0);
let rotate = CGAffineTransform(rotationAngle: -90)
checkButton.alpha = 0
nextView.transform = shrink.concatenating(rotate)
}
and then in view did appear I perform the animations
override func viewDidAppear(_ animated: Bool) {
UIView.animate(withDuration: 0.35, animations: {
let grow = CGAffineTransform(scaleX: 1, y: 1);
let rotate = CGAffineTransform(rotationAngle: 0)
self.checkButton.alpha = 1
self.nextView.transform = grow.concatenating(rotate)
})
}
But only the grow animation works? How do i get it so it grows from scale 0 to scale 1 and rotates from 90 degrees to 0 degrees?
Cheers
Upvotes: 2
Views: 4867
Reputation: 1021
I'm not quite sure why starting at scale 0 prevents it from rotating, but bumping up the scale on willAppear did the trick.
override func viewWillAppear(_ animated: Bool) {
let shrink = CGAffineTransform(scaleX: 0.01, y: 0.01);
let rotate = CGAffineTransform(rotationAngle: -90)
checkButton.alpha = 0
nextView.transform = shrink.concatenating(rotate)
}
override func viewDidAppear(_ animated: Bool) {
UIView.animate(withDuration: 0.35, animations: {
let grow = CGAffineTransform(scaleX: 1, y: 1);
let rotate = CGAffineTransform(rotationAngle: 0)
self.checkButton.alpha = 1
self.nextView.transform = grow.concatenating(rotate)
})
}
Upvotes: 4