Combining an animation of an UIImageView with a tr

2020-04-14 09:46发布

I am doing a transition of an UIImageView's image and would also like to move the image view at the same time. The results so far is that the image transitions, but not while moving.

class ViewController: UIViewController {

    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var imageViewTopConstraint: NSLayoutConstraint!

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        UIView.transition(with: imageView, duration: 2.0, options: .transitionCrossDissolve, animations: {
            self.imageView.image = UIImage(named: "otherImage")
        }, completion: nil)

        imageViewTopConstraint.constant = 200

        UIView.animate(withDuration: 2.0) {
            self.view.layoutIfNeeded()
        }
    }

}

Any ideas on how to solve this?

1条回答
啃猪蹄的小仙女
2楼-- · 2020-04-14 10:10

You can put your imageView inside a container, then animate the constraints of the container while doing the transition on the imageView.

查看更多
登录 后发表回答