将UIImageView的动画与过渡相结合

时间:2017-02-23 17:10:47

标签: ios swift uiimageview core-animation

我正在进行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()
        }
    }

}

关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:3)

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