Translation Image Animation Swift 5.



This blog is providing how to TranslationX and TranslationY image using animation. here we are using UIView animation with CGAffineTransform. code is programmatically. 


Full Code With Translation Image:
override func viewDidLoad() {
    super.viewDidLoad()

    // ImageView with Image
    let imageV = UIImageView(frame: CGRect(x: 50, y: 100, width: 150, height: 100))
    imageV.center = view.center
    imageV.image = UIImage(named: "devImage", in: Bundle(for: type(of: self)), compatibleWith: nil)
    view.addSubview(imageV)

    // Scaling

    UIView.animate(withDuration: 6.0, animations: {
        imageV.transform = CGAffineTransform(translationX: 0, y: -100)

    }) { (complete) in
        UIView.animate(withDuration: 6.0, animations: {
            imageV.transform = CGAffineTransform(translationX: 0, y: 100)
        })
    }

}

Output:



Thanks

Translation Image Animation Swift 5. Translation Image Animation Swift 5. Reviewed by KIRIT MODI on 23:32:00 Rating: 5

No comments:

Powered by Blogger.