将UIImageView的动画与过渡相结合 [英] Combining an animation of an UIImageView with a transition

查看:103
本文介绍了将UIImageView的动画与过渡相结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在过渡UIImageView的图像,并且还希望同时移动图像视图。到目前为止,结果是图像过渡了,但移动时没有。

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?

推荐答案

您可以将imageView放在容器中,然后在对imageView进行过渡时动画化容器的约束。

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

这篇关于将UIImageView的动画与过渡相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆