I'm trying to do some animation for a UIImageView (only zooming out)
1- I set the frame to be bigger than the screen to make it zoomed in like so :
private lazy var imageView: UIImageView = {
let image = UIImageView()
image.frame = CGRect(x: 0, y: 0, width: view.frame.width + 300, height: view.frame.height + 300)
image.center = view.center
image.image = UIImage(named: "1111")
image.contentMode = .scaleAspectFill
return image
}()
and I want to make the frame go back to the screen size like so :
func firstAnimation() {
UIView.animate(withDuration: 15, animations: {
// HERE
self.imageView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
}) { (finished) in
self.secondAnimation()
}
}
I didn't work with me unfortunately.
Here the full class code : github
Use CGAffineTransform.identity
to resize your image to it's first identity
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
// HERE
self.imageview.transform = CGAffineTransform.identity.scaledBy(x: 2, y: 2) // Scale your image
}) { (finished) in
UIView.animate(withDuration: 1, animations: {
self.imageview.transform = CGAffineTransform.identity // undo in 1 seconds
})
}
Code for zoom in:
[UIView animateWithDuration:1.0 animations:^{
imgv.transform = CGAffineTransformMakeScale(1.0,1.0);
}completion:^(BOOL finished){
}];
Code for zoom out:
[UIView animateWithDuration:1.0 animations:^{
imgv.transform = CGAffineTransformMakeScale(0.1,0.1);
}completion:^(BOOL finished){
imgv.transform = CGAffineTransformMakeScale(.0,.0);
}];
Here imvv
is my UIImageview
object. You can replace it with your view object. In zoom out
code we hide the view by scaling
it to 0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With