首页 > 解决方案 > Swift UIImage Animation - 从框架外飞入框架

问题描述

我目前正在尝试查看是否有任何教程或一些关于如何动画 UIImages 从框架外飞入框架的参考。我目前正在尝试使用底部代码,但它没有产生我想要的。

我正在创建一个 DC Universe 介绍页面,其中主要角色将一次飞入其中,并形成一个很好的角色集合,我认为这将非常酷。

UIView.animate(withDuration: 0.5, animations: {
        self.superManImage.frame.origin.x -= 200 }, completion: nil)

标签: swiftanimationuiimageuiviewanimation

解决方案


到目前为止,这对我有用。蝙蝠侠图像从顶部飞入,超人图像从左侧飞入。

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

    superManImage.center.x -= view.bounds.width
    batManImage.center.y -= view.bounds.width

}

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

    UIView.animate(withDuration: 0.8, delay: 1.0, options: [], animations: {
        self.superManImage.center.x += self.view.bounds.width
    }, completion: nil)

    UIView.animate(withDuration: 0.5, delay: 0.3, options: [], animations: {
        self.batManImage.center.y += self.view.bounds.width
    }, completion: nil)
}

推荐阅读