Combining an animation of an UIImageView with a transition

自作多情 提交于 2019-12-02 02:17:49

问题


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:


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



来源:https://stackoverflow.com/questions/42422131/combining-an-animation-of-an-uiimageview-with-a-transition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!