将 UIImageView 的动画与过渡相结合

Combining an animation of an UIImageView with a transition

我正在对 UIImageView 的图像进行转换,同时还想移动图像视图。到目前为止的结果是图像过渡,但不是在移动时。

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()
        }
    }

}

关于如何解决这个问题有什么想法吗?

您可以将您的 imageView 放入容器中,然后在对 imageView 进行转换时为容器的约束设置动画。